Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active May 8, 2021 04:14
Show Gist options
  • Save percybolmer/557faf0ca1420779ea1b9387e4735c44 to your computer and use it in GitHub Desktop.
Save percybolmer/557faf0ca1420779ea1b9387e4735c44 to your computer and use it in GitHub Desktop.
Simple staking test
const DevToken = artifacts.require("DevToken");
contract("DevToken", async accounts => {
// Stake 100 is used to stake 100 tokens and see that stake is added correctly and money burned
it("Stake 100", async () => {
// Deploy the DevToken and await it, store the results inside devToken
devToken = await DevToken.deployed();
// Set owner, user and a stake_amount
let owner = accounts[0];
let stake_amount = 100
// Get init balance of user
balance = await devToken.balanceOf(owner)
// Stake the amount, notice the FROM parameter which specifes what the msg.sender address will be
devToken.stake(stake_amount, { from: owner});
after_balance = await devToken.balanceOf(owner)
// Assert if his balance is equal to 100000- stake
assert.equal(after_balance.toNumber(), balance - stake_amount);
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment