Skip to content

Commit

Permalink
feat: add test for mintable bouncer
Browse files Browse the repository at this point in the history
  • Loading branch information
shrugs committed Sep 3, 2018
1 parent 081f5ca commit 121c6ed
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 4 deletions.
6 changes: 3 additions & 3 deletions kata-token/test/EscrowedERC20Bouncer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract(
this.mock = await EscrowedERC20Bouncer.new(bouncerSigner, {
from: deployer
});
this.signFor = getBouncerSigner(this.mock, bouncerSigner);
this.sign = getBouncerSigner(this.mock, bouncerSigner);
});

context("with nothing in it", function() {
Expand All @@ -55,7 +55,7 @@ contract(
});

it("allows bouncer to withdraw for beneficiary via delegate", async function() {
const sig = await this.signFor(executor, "withdraw", [
const sig = await this.sign("withdraw", [
++nonce,
this.token.address,
beneficiary,
Expand Down Expand Up @@ -85,7 +85,7 @@ contract(

it("allows bouncer to withdraw for beneficiary via delegate for n times", async function() {
for (let i = 1; i < COUNT + 1; i++) {
const sig = await this.signFor(executor, "withdraw", [
const sig = await this.sign("withdraw", [
++nonce,
this.token.address,
beneficiary,
Expand Down
73 changes: 73 additions & 0 deletions kata-token/test/MintableERC20Bouncer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const b = require("buidler");
const { expectThrow } = require("./helpers/expectThrow");
const { getBouncerSigner } = require("./helpers/sign");

const MockToken = b.artifacts.require("MockToken");
const MintableERC20Bouncer = b.artifacts.require("MintableERC20Bouncer");

const gas = 7000000; // work around gas estimation issues

require("chai")
.use(require("chai-bignumber")(b.web3.BigNumber))
.should();

const COUNT = 10;
let nonce = 0;

contract(
"MintableERC20Bouncer",
([_, deployer, bouncerSigner, executor, beneficiary]) => {
beforeEach(async function() {
this.token = await MockToken.new("Test", "TEST", 18, { from: deployer });
this.mock = await MintableERC20Bouncer.new(bouncerSigner, {
from: deployer
});

this.sign = getBouncerSigner(this.mock, bouncerSigner);
});

context("with mintable permission", function() {
beforeEach(async function() {
await this.token.transferOwnership(this.mock.address, {
from: deployer
});
});

it("allows bouncer to mint for beneficiary via delegate", async function() {
const sig = await this.sign("mint", [
++nonce,
this.token.address,
beneficiary,
1
]);

await this.mock.mint(nonce, this.token.address, beneficiary, 1, sig, {
from: executor,
gas
});

(await this.token.balanceOf(beneficiary)).should.be.bignumber.equal(1);
});

it("allows bouncer to mint for beneficiary via delegate for n times", async function() {
for (let i = 1; i < COUNT + 1; i++) {
const sig = await this.sign("mint", [
++nonce,
this.token.address,
beneficiary,
1
]);

await this.mock.mint(nonce, this.token.address, beneficiary, 1, sig, {
from: executor,
gas
});

(await this.token.balanceOf(beneficiary)).should.be.bignumber.equal(
i
);
}
});
});
}
);
1 change: 0 additions & 1 deletion kata-token/test/helpers/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const transformToFullName = function(json) {
* @param methodArgs any[]
*/
const getBouncerSigner = (contract, signer) => async (
redeemer,
methodName,
methodArgs = []
) => {
Expand Down

0 comments on commit 121c6ed

Please sign in to comment.