Created
May 15, 2021 20:31
-
-
Save percybolmer/b4dfcbb8c389bb1b3dd1875446944bf7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
it ("allow account some allowance", async() => { | |
devToken = await DevToken.deployed(); | |
try{ | |
// Give account(0) access too 100 tokens on creator | |
await devToken.approve('0x0000000000000000000000000000000000000000', 100); | |
}catch(error){ | |
assert.equal(error.reason, 'DevToken: approve cannot be to zero address', "Should be able to approve zero address"); | |
} | |
try{ | |
// Give account 1 access too 100 tokens on zero account | |
await devToken.approve(accounts[1], 100); | |
}catch(error){ | |
assert.fail(error); // shold not fail | |
} | |
// Verify by checking allowance | |
let allowance = await devToken.allowance(accounts[0], accounts[1]); | |
assert.equal(allowance.toNumber(), 100, "Allowance was not correctly inserted"); | |
}) | |
it("transfering with allowance", async() => { | |
devToken = await DevToken.deployed(); | |
try{ | |
// Account 1 should have 100 tokens by now to use on account 0 | |
// lets try using more | |
await devToken.transferFrom(accounts[0], accounts[2], 200, { from: accounts[1] } ); | |
}catch(error){ | |
assert.equal(error.reason, "DevToken: You cannot spend that much on this account", "Failed to detect overspending") | |
} | |
let init_allowance = await devToken.allowance(accounts[0], accounts[1]); | |
console.log("init balalnce: ", init_allowance.toNumber()) | |
try{ | |
// Account 1 should have 100 tokens by now to use on account 0 | |
// lets try using more | |
let worked = await devToken.transferFrom(accounts[0], accounts[2], 50, {from:accounts[1]}); | |
}catch(error){ | |
assert.fail(error); | |
} | |
// Make sure allowance was changed | |
let allowance = await devToken.allowance(accounts[0], accounts[1]); | |
assert.equal(allowance.toNumber(), 50, "The allowance should have been decreased by 50") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment