Last active
April 7, 2020 07:30
-
-
Save Aniket-Engg/c366e1db48b2b19f92d9df758375c91c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
address account0; | |
address account1; | |
address account2; | |
/// Initiate accounts variable | |
function beforeAll() public { | |
account0 = TestsAccounts.getAccount(0); | |
account1 = TestsAccounts.getAccount(1); | |
account2 = TestsAccounts.getAccount(2); | |
} | |
/// Test if initial owner is set correctly | |
function testInitialOwner() public { | |
// account-0 is default account, so current owner should be account0 | |
Assert.equal(getOwner(), account0, 'owner should be account-0'); | |
} | |
/// Update owner. This method will be called by account0 as there is not custom sender appointed | |
function updateOwnerOnce() public { | |
// check method call is as expected | |
Assert.ok(msg.sender == account0, 'caller should default account i.e. account0'); | |
// update owner address to account1 | |
updateOwner(account1); | |
// check if owner is set to expected account | |
Assert.equal(getOwner(), account1, 'owner should be updated to account1'); | |
} | |
/// Update owner again by defining custom sender | |
/// #sender: account-1 | |
function updateOwnerOnceAgain() public { | |
// check if caller is custom and is as expected | |
Assert.ok(msg.sender == account1, 'caller should be custom account i.e. account1'); | |
// update owner address to account2. This will be successful because account1 is current owner & caller both | |
updateOwner(account2); | |
// check if owner is set to expected account i.e. account2 | |
Assert.equal(getOwner(), account2, 'owner should be updated to account2'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment