Skip to content

Commit c645323

Browse files
committed
Add unhappy paths
1 parent a9103af commit c645323

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

contracts/simple_greeter.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ contract SimpleGreeter {
1313
}
1414

1515
function setSuperGreeting(string calldata greeting) external {
16+
require(msg.sender == owner, "Only owner");
1617
_greeting = greeting;
1718
}
1819
}

lib/rspec/eth/helper_methods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def accounts
2424

2525
def contract_path
2626
@contract_path ||= begin
27-
filename = self.class.to_s.split("::").last.underscore
27+
filename = self.class.metadata[:file_path].split('/').last.gsub('_spec', '').gsub('.rb', '')
2828
File.join(RSpec::Eth::Config.contracts_path, "#{filename}.sol")
2929
end
3030
end

spec/rspec/integration/simple_greeter_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,22 @@
1212

1313
it 'has owner' do
1414
expect(contract.call.owner).to be_present
15+
expect(contract.call.owner).to eq(accounts[0][2..-1])
1516
end
1617

1718
it 'changes message' do
1819
contract.transact_and_wait.set_super_greeting("Yo")
1920

2021
expect(contract.call.greet).to eq("Yo")
2122
end
23+
24+
context 'when sender not owner' do
25+
before { contract.sender = accounts[1] }
26+
27+
it 'trying to set not from owner' do
28+
expect {
29+
contract.transact_and_wait.set_super_greeting("Yo")
30+
}.to raise_exception(IOError, "VM Exception while processing transaction: revert Only owner")
31+
end
32+
end
2233
end

0 commit comments

Comments
 (0)