Skip to content
This repository was archived by the owner on Mar 11, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions test/metacoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ const MetaCoin = artifacts.require("MetaCoin");
contract('MetaCoin', (accounts) => {
it('should put 10000 MetaCoin in the first account', async () => {
const metaCoinInstance = await MetaCoin.deployed();
const balance = await metaCoinInstance.getBalance.call(accounts[0]);
const balance = await metaCoinInstance.getBalance(accounts[0]);

assert.equal(balance.valueOf(), 10000, "10000 wasn't in the first account");
});

it('should call a function that depends on a linked library', async () => {
const metaCoinInstance = await MetaCoin.deployed();
const metaCoinBalance = (await metaCoinInstance.getBalance.call(accounts[0])).toNumber();
const metaCoinEthBalance = (await metaCoinInstance.getBalanceInEth.call(accounts[0])).toNumber();
const metaCoinBalance = (await metaCoinInstance.getBalance(accounts[0])).toNumber();
const metaCoinEthBalance = (await metaCoinInstance.getBalanceInEth(accounts[0])).toNumber();

assert.equal(metaCoinEthBalance, 2 * metaCoinBalance, 'Library function returned unexpected function, linkage may be broken');
});

it('should send coin correctly', async () => {
const metaCoinInstance = await MetaCoin.deployed();

Expand All @@ -22,16 +24,16 @@ contract('MetaCoin', (accounts) => {
const accountTwo = accounts[1];

// Get initial balances of first and second account.
const accountOneStartingBalance = (await metaCoinInstance.getBalance.call(accountOne)).toNumber();
const accountTwoStartingBalance = (await metaCoinInstance.getBalance.call(accountTwo)).toNumber();
const accountOneStartingBalance = (await metaCoinInstance.getBalance(accountOne)).toNumber();
const accountTwoStartingBalance = (await metaCoinInstance.getBalance(accountTwo)).toNumber();

// Make transaction from first account to second.
const amount = 10;
await metaCoinInstance.sendCoin(accountTwo, amount, { from: accountOne });

// Get balances of first and second account after the transactions.
const accountOneEndingBalance = (await metaCoinInstance.getBalance.call(accountOne)).toNumber();
const accountTwoEndingBalance = (await metaCoinInstance.getBalance.call(accountTwo)).toNumber();
const accountOneEndingBalance = (await metaCoinInstance.getBalance(accountOne)).toNumber();
const accountTwoEndingBalance = (await metaCoinInstance.getBalance(accountTwo)).toNumber();


assert.equal(accountOneEndingBalance, accountOneStartingBalance - amount, "Amount wasn't correctly taken from the sender");
Expand Down