pragma solidity >=0.4.22 <0.7.0; import "remix_tests.sol"; // this import is automatically injected by Remix import "remix_accounts.sol"; import "./Sender.sol"; // Inherit 'Sender' contract contract SenderTest is Sender { /// Define variables referring to different accounts address acc0; address acc1; address acc2; /// Initiate accounts variable function beforeAll() public { acc0 = TestsAccounts.getAccount(0); acc1 = TestsAccounts.getAccount(1); acc2 = TestsAccounts.getAccount(2); } /// Test if initial owner is set correctly function testInitialOwner() public { // account at zero index (account-0) is default account, so current owner should be acc0 Assert.equal(getOwner(), acc0, 'owner should be acc0'); } /// Update owner first time /// This method will be called by default account(account-0) as there is no custom sender defined function updateOwnerOnce() public { // check method caller is as expected Assert.ok(msg.sender == acc0, 'caller should be default account i.e. acc0'); // update owner address to acc1 updateOwner(acc1); // check if owner is set to expected account Assert.equal(getOwner(), acc1, 'owner should be updated to acc1'); } /// Update owner again by defining custom sender /// #sender: account-1 (sender is account at index '1') function updateOwnerOnceAgain() public { // check if caller is custom and is as expected Assert.ok(msg.sender == acc1, 'caller should be custom account i.e. acc1'); // update owner address to acc2. This will be successful because acc1 is current owner & caller both updateOwner(acc2); // check if owner is set to expected account i.e. account2 Assert.equal(getOwner(), acc2, 'owner should be updated to acc2'); } }
0.6.1