@0xcert/ethereum-erc20-contracts
Advanced tools
Comparing version 2.0.0 to 2.0.1-beta0
{ | ||
"files": { | ||
"packages/0xcert-ethereum-erc20-contracts/.solhint.json": "c72aedffae70ae4b1e2830449ec0e140eb7fb14a", | ||
"packages/0xcert-ethereum-erc20-contracts/CHANGELOG.json": "33c8182e0da201c181f5d2fde96d9899b69d06b9", | ||
"packages/0xcert-ethereum-erc20-contracts/CHANGELOG.md": "318b318b6a0787f939c0a6842e6cd91696f70346", | ||
"packages/0xcert-ethereum-erc20-contracts/README.md": "06e2df064ffa7d6321a6878eca16873f6491feca", | ||
"packages/0xcert-ethereum-erc20-contracts/nodemon.json": "82b893373db9861f1df4b55d8ea68a5d37b118de", | ||
"packages/0xcert-ethereum-erc20-contracts/package.json": "87d84893cad2e0c001a6616a2bccd443e20f7eb9", | ||
"packages/0xcert-ethereum-erc20-contracts/src/contracts/dapp-token.sol": "97c065de5d543fdf4b1f2416176b0897f64e4ea3", | ||
"packages/0xcert-ethereum-erc20-contracts/src/contracts/erc20.sol": "7063bcef324d2b1391e684b0569d0cf050c19ebe", | ||
"packages/0xcert-ethereum-erc20-contracts/src/contracts/migration-receiver.sol": "7ebb1f8896a430fc52346b82db5ea7a9a6c1257e", | ||
"packages/0xcert-ethereum-erc20-contracts/src/contracts/mocks/dapp-token-mock.sol": "625853afc8563e886aca1a3c367af3f408e33909", | ||
"packages/0xcert-ethereum-erc20-contracts/src/contracts/mocks/token-mock.sol": "88dcaa034df424db1ba597a886f405cb4ca2ee2e", | ||
"packages/0xcert-ethereum-erc20-contracts/src/contracts/token.sol": "3642373fc1692b7e4cdf642f321955dec3e0a4ae", | ||
"packages/0xcert-ethereum-erc20-contracts/src/contracts/zxc-burner.sol": "7378001e358455608449daffbb026ec4435c3e23", | ||
"packages/0xcert-ethereum-erc20-contracts/src/contracts/zxc.sol": "634a705d3e9bc281e8bcba06e1d9af2a3551756b", | ||
"packages/0xcert-ethereum-erc20-contracts/src/core/types.ts": "be9414515fb92f954d214de5f1313a2348cb20b2", | ||
"packages/0xcert-ethereum-erc20-contracts/src/index.ts": "a7b884b8a2b9ec2a03c20192d83ff3d49c3b6cdd", | ||
"packages/0xcert-ethereum-erc20-contracts/src/tests/dapp-token.test.ts": "962d6f31c7b41f98a6f91c6f87835c63e368c33f", | ||
"packages/0xcert-ethereum-erc20-contracts/src/tests/helpers/common.ts": "28cfef796c13a9ec6b38a6623bab6d270ac6c202", | ||
"packages/0xcert-ethereum-erc20-contracts/src/tests/mocks/zxc-mock.sol": "e54852daa7ce012679501f7c1f07481b8e771291", | ||
"packages/0xcert-ethereum-erc20-contracts/src/tests/token.test.ts": "efe664b4bf7ef62cfbb3e142dfc55c0d2ac5192d", | ||
"packages/0xcert-ethereum-erc20-contracts/src/tests/zxc-burner.test.ts": "a598736f8fb609986f33d7f349b6da150c96faf1", | ||
"packages/0xcert-ethereum-erc20-contracts/tsconfig.json": "aaa461c172cf0c93d58ffeef8e3ead76fe299b2e", | ||
"packages/0xcert-ethereum-erc20-contracts/tslint.json": "c57b3f0cdb7aa74ab2ab02888380f613589cbe66" | ||
}, | ||
"files": {}, | ||
"arguments": "npm run clean && npx specron compile && npx tsc " | ||
} |
@@ -10,2 +10,3 @@ import { Spec } from '@specron/spec'; | ||
sara?: string; | ||
zeroAddress?: string; | ||
ttProxy?: string; | ||
@@ -12,0 +13,0 @@ decimalsMul?: any; |
@@ -14,2 +14,3 @@ "use strict"; | ||
const __1 = require(".."); | ||
const common = require("./helpers/common"); | ||
const spec = new spec_1.Spec(); | ||
@@ -23,2 +24,3 @@ spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { | ||
ctx.set('ttProxy', accounts[4]); | ||
ctx.set('zeroAddress', '0x0000000000000000000000000000000000000000'); | ||
})); | ||
@@ -378,2 +380,200 @@ spec.beforeEach((ctx) => __awaiter(void 0, void 0, void 0, function* () { | ||
})); | ||
spec.test('correctly approves with signature', (ctx) => __awaiter(void 0, void 0, void 0, function* () { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() + 3600; | ||
yield token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
yield dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
const claim = yield dappToken.instance.methods.generateClaim(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).call(); | ||
const signature = yield ctx.web3.eth.sign(claim, owner); | ||
const signatureData = { | ||
r: signature.substr(0, 66), | ||
s: `0x${signature.substr(66, 64)}`, | ||
v: parseInt(`0x${signature.substr(130, 2)}`) + 27, | ||
kind: 0, | ||
}; | ||
const signatureDataTuple = ctx.tuple(signatureData); | ||
const logs = yield dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob }); | ||
const actualAllowance = yield dappToken.instance.methods.allowance(owner, sara).call(); | ||
const bobBalance = yield dappToken.instance.methods.balanceOf(bob).call(); | ||
ctx.not(logs.events.Approval, undefined); | ||
ctx.not(logs.events.Transfer, undefined); | ||
ctx.is(actualAllowance.toString(), tokenAmount.toString()); | ||
ctx.is(bobBalance.toString(), feeAmount.toString()); | ||
})); | ||
spec.test('correctly approves with signature with any performer', (ctx) => __awaiter(void 0, void 0, void 0, function* () { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const zeroAddress = ctx.get('zeroAddress'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() + 3600; | ||
yield token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
yield dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
const claim = yield dappToken.instance.methods.generateClaim(owner, sara, tokenAmount.toString(), zeroAddress, feeAmount.toString(), seed, expiration).call(); | ||
const signature = yield ctx.web3.eth.sign(claim, owner); | ||
const signatureData = { | ||
r: signature.substr(0, 66), | ||
s: `0x${signature.substr(66, 64)}`, | ||
v: parseInt(`0x${signature.substr(130, 2)}`) + 27, | ||
kind: 0, | ||
}; | ||
const signatureDataTuple = ctx.tuple(signatureData); | ||
const logs = yield dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), zeroAddress, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob }); | ||
const actualAllowance = yield dappToken.instance.methods.allowance(owner, sara).call(); | ||
const bobBalance = yield dappToken.instance.methods.balanceOf(bob).call(); | ||
ctx.not(logs.events.Approval, undefined); | ||
ctx.not(logs.events.Transfer, undefined); | ||
ctx.is(actualAllowance.toString(), tokenAmount.toString()); | ||
ctx.is(bobBalance.toString(), feeAmount.toString()); | ||
})); | ||
spec.test('fails approving with signature if signature is invalid', (ctx) => __awaiter(void 0, void 0, void 0, function* () { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() + 3600; | ||
yield token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
yield dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
const claim = yield dappToken.instance.methods.generateClaim(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).call(); | ||
const signature = yield ctx.web3.eth.sign(claim, bob); | ||
const signatureData = { | ||
r: signature.substr(0, 66), | ||
s: `0x${signature.substr(66, 64)}`, | ||
v: parseInt(`0x${signature.substr(130, 2)}`) + 27, | ||
kind: 0, | ||
}; | ||
const signatureDataTuple = ctx.tuple(signatureData); | ||
yield ctx.reverts(() => dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob }), '010007'); | ||
})); | ||
spec.test('fails approving with signature if claim has expired', (ctx) => __awaiter(void 0, void 0, void 0, function* () { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() - 3600; | ||
yield token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
yield dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
const claim = yield dappToken.instance.methods.generateClaim(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).call(); | ||
const signature = yield ctx.web3.eth.sign(claim, owner); | ||
const signatureData = { | ||
r: signature.substr(0, 66), | ||
s: `0x${signature.substr(66, 64)}`, | ||
v: parseInt(`0x${signature.substr(130, 2)}`) + 27, | ||
kind: 0, | ||
}; | ||
const signatureDataTuple = ctx.tuple(signatureData); | ||
yield ctx.reverts(() => dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob }), '010009'); | ||
})); | ||
spec.test('fails approving with signature if claim has already been performed', (ctx) => __awaiter(void 0, void 0, void 0, function* () { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() + 3600; | ||
yield token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
yield dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
const claim = yield dappToken.instance.methods.generateClaim(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).call(); | ||
const signature = yield ctx.web3.eth.sign(claim, owner); | ||
const signatureData = { | ||
r: signature.substr(0, 66), | ||
s: `0x${signature.substr(66, 64)}`, | ||
v: parseInt(`0x${signature.substr(130, 2)}`) + 27, | ||
kind: 0, | ||
}; | ||
const signatureDataTuple = ctx.tuple(signatureData); | ||
yield dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob }); | ||
yield ctx.reverts(() => dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob }), '010008'); | ||
})); | ||
spec.test('fails approving with signature if claim has been canceled', (ctx) => __awaiter(void 0, void 0, void 0, function* () { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() + 3600; | ||
yield token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
yield dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
const claim = yield dappToken.instance.methods.generateClaim(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).call(); | ||
const signature = yield ctx.web3.eth.sign(claim, owner); | ||
const signatureData = { | ||
r: signature.substr(0, 66), | ||
s: `0x${signature.substr(66, 64)}`, | ||
v: parseInt(`0x${signature.substr(130, 2)}`) + 27, | ||
kind: 0, | ||
}; | ||
const signatureDataTuple = ctx.tuple(signatureData); | ||
yield dappToken.instance.methods.cancelApproveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).send({ from: owner }); | ||
yield ctx.reverts(() => dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob }), '010011'); | ||
})); | ||
spec.test('fails cancel approve with signature if you are not the approver', (ctx) => __awaiter(void 0, void 0, void 0, function* () { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() + 3600; | ||
yield token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
yield dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
yield ctx.reverts(() => dappToken.instance.methods.cancelApproveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).send({ from: bob }), '010012'); | ||
})); | ||
spec.test('fails approving with signature if signature kind is invalid', (ctx) => __awaiter(void 0, void 0, void 0, function* () { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() + 3600; | ||
yield token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
yield dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
const claim = yield dappToken.instance.methods.generateClaim(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).call(); | ||
const signature = yield ctx.web3.eth.sign(claim, owner); | ||
const signatureData = { | ||
r: signature.substr(0, 66), | ||
s: `0x${signature.substr(66, 64)}`, | ||
v: parseInt(`0x${signature.substr(130, 2)}`) + 27, | ||
kind: 3, | ||
}; | ||
const signatureDataTuple = ctx.tuple(signatureData); | ||
yield ctx.reverts(() => dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob })); | ||
})); | ||
spec.test('throws when trying to transferFrom more than allowed amount', (ctx) => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -380,0 +580,0 @@ const token = ctx.get('token'); |
{ | ||
"name": "@0xcert/ethereum-erc20-contracts", | ||
"version": "2.0.0", | ||
"version": "2.0.1-beta0", | ||
"description": "Smart contract implementation of the ERC-20 standard on the Ethereum blockchain.", | ||
@@ -80,3 +80,3 @@ "scripts": { | ||
"@specron/flattener": "0.16.0", | ||
"@0xcert/ethereum-utils-contracts": "2.0.0", | ||
"@0xcert/ethereum-utils-contracts": "2.0.1-beta0", | ||
"solc": "0.6.1", | ||
@@ -83,0 +83,0 @@ "solhint": "2.3.0", |
@@ -13,2 +13,3 @@ import { Spec } from '@specron/spec'; | ||
sara?: string; | ||
zeroAddress?: string; | ||
ttProxy?: string; | ||
@@ -28,2 +29,3 @@ decimalsMul?: any; | ||
ctx.set('ttProxy', accounts[4]); | ||
ctx.set('zeroAddress', '0x0000000000000000000000000000000000000000'); | ||
}); | ||
@@ -451,2 +453,224 @@ | ||
spec.test('correctly approves with signature', async (ctx) => { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() + 3600; | ||
await token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
await dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
const claim = await dappToken.instance.methods.generateClaim(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).call(); | ||
const signature = await ctx.web3.eth.sign(claim, owner); | ||
const signatureData = { | ||
r: signature.substr(0, 66), | ||
s: `0x${signature.substr(66, 64)}`, | ||
v: parseInt(`0x${signature.substr(130, 2)}`) + 27, | ||
kind: 0, | ||
}; | ||
const signatureDataTuple = ctx.tuple(signatureData); | ||
const logs = await dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob }); | ||
const actualAllowance = await dappToken.instance.methods.allowance(owner, sara).call(); | ||
const bobBalance = await dappToken.instance.methods.balanceOf(bob).call(); | ||
ctx.not(logs.events.Approval, undefined); | ||
ctx.not(logs.events.Transfer, undefined); | ||
ctx.is(actualAllowance.toString(), tokenAmount.toString()); | ||
ctx.is(bobBalance.toString(), feeAmount.toString()); | ||
}); | ||
spec.test('correctly approves with signature with any performer', async (ctx) => { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const zeroAddress = ctx.get('zeroAddress'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() + 3600; | ||
await token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
await dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
const claim = await dappToken.instance.methods.generateClaim(owner, sara, tokenAmount.toString(), zeroAddress, feeAmount.toString(), seed, expiration).call(); | ||
const signature = await ctx.web3.eth.sign(claim, owner); | ||
const signatureData = { | ||
r: signature.substr(0, 66), | ||
s: `0x${signature.substr(66, 64)}`, | ||
v: parseInt(`0x${signature.substr(130, 2)}`) + 27, | ||
kind: 0, | ||
}; | ||
const signatureDataTuple = ctx.tuple(signatureData); | ||
const logs = await dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), zeroAddress, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob }); | ||
const actualAllowance = await dappToken.instance.methods.allowance(owner, sara).call(); | ||
const bobBalance = await dappToken.instance.methods.balanceOf(bob).call(); | ||
ctx.not(logs.events.Approval, undefined); | ||
ctx.not(logs.events.Transfer, undefined); | ||
ctx.is(actualAllowance.toString(), tokenAmount.toString()); | ||
ctx.is(bobBalance.toString(), feeAmount.toString()); | ||
}); | ||
spec.test('fails approving with signature if signature is invalid', async (ctx) => { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() + 3600; | ||
await token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
await dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
const claim = await dappToken.instance.methods.generateClaim(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).call(); | ||
const signature = await ctx.web3.eth.sign(claim, bob); | ||
const signatureData = { | ||
r: signature.substr(0, 66), | ||
s: `0x${signature.substr(66, 64)}`, | ||
v: parseInt(`0x${signature.substr(130, 2)}`) + 27, | ||
kind: 0, | ||
}; | ||
const signatureDataTuple = ctx.tuple(signatureData); | ||
await ctx.reverts(() => dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob }), '010007'); | ||
}); | ||
spec.test('fails approving with signature if claim has expired', async (ctx) => { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() - 3600; | ||
await token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
await dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
const claim = await dappToken.instance.methods.generateClaim(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).call(); | ||
const signature = await ctx.web3.eth.sign(claim, owner); | ||
const signatureData = { | ||
r: signature.substr(0, 66), | ||
s: `0x${signature.substr(66, 64)}`, | ||
v: parseInt(`0x${signature.substr(130, 2)}`) + 27, | ||
kind: 0, | ||
}; | ||
const signatureDataTuple = ctx.tuple(signatureData); | ||
await ctx.reverts(() => dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob }), '010009'); | ||
}); | ||
spec.test('fails approving with signature if claim has already been performed', async (ctx) => { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() + 3600; | ||
await token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
await dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
const claim = await dappToken.instance.methods.generateClaim(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).call(); | ||
const signature = await ctx.web3.eth.sign(claim, owner); | ||
const signatureData = { | ||
r: signature.substr(0, 66), | ||
s: `0x${signature.substr(66, 64)}`, | ||
v: parseInt(`0x${signature.substr(130, 2)}`) + 27, | ||
kind: 0, | ||
}; | ||
const signatureDataTuple = ctx.tuple(signatureData); | ||
await dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob }); | ||
await ctx.reverts(() => dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob }), '010008'); | ||
}); | ||
spec.test('fails approving with signature if claim has been canceled', async (ctx) => { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() + 3600; | ||
await token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
await dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
const claim = await dappToken.instance.methods.generateClaim(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).call(); | ||
const signature = await ctx.web3.eth.sign(claim, owner); | ||
const signatureData = { | ||
r: signature.substr(0, 66), | ||
s: `0x${signature.substr(66, 64)}`, | ||
v: parseInt(`0x${signature.substr(130, 2)}`) + 27, | ||
kind: 0, | ||
}; | ||
const signatureDataTuple = ctx.tuple(signatureData); | ||
await dappToken.instance.methods.cancelApproveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).send({ from: owner }); | ||
await ctx.reverts(() => dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob }), '010011'); | ||
}); | ||
spec.test('fails cancel approve with signature if you are not the approver', async (ctx) => { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() + 3600; | ||
await token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
await dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
await ctx.reverts(() => dappToken.instance.methods.cancelApproveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).send({ from: bob }), '010012'); | ||
}); | ||
spec.test('fails approving with signature if signature kind is invalid', async (ctx) => { | ||
const dappToken = ctx.get('dappToken'); | ||
const token = ctx.get('token'); | ||
const owner = ctx.get('owner'); | ||
const bob = ctx.get('bob'); | ||
const sara = ctx.get('sara'); | ||
const decimalsMul = ctx.get('decimalsMul'); | ||
const tokenAmount = decimalsMul.mul(new ctx.web3.utils.BN('100')); | ||
const feeAmount = decimalsMul.mul(new ctx.web3.utils.BN('10')); | ||
const seed = common.getCurrentTime(); | ||
const expiration = common.getCurrentTime() + 3600; | ||
await token.instance.methods.approve(dappToken.receipt._address, tokenAmount.toString()).send({ from: owner }); | ||
await dappToken.instance.methods.deposit(tokenAmount.toString(), owner).send({ from: owner }); | ||
const claim = await dappToken.instance.methods.generateClaim(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration).call(); | ||
const signature = await ctx.web3.eth.sign(claim, owner); | ||
const signatureData = { | ||
r: signature.substr(0, 66), | ||
s: `0x${signature.substr(66, 64)}`, | ||
v: parseInt(`0x${signature.substr(130, 2)}`) + 27, | ||
kind: 3, | ||
}; | ||
const signatureDataTuple = ctx.tuple(signatureData); | ||
await ctx.reverts(() => dappToken.instance.methods.approveWithSignature(owner, sara, tokenAmount.toString(), bob, feeAmount.toString(), seed, expiration, signatureDataTuple).send({ from: bob })); | ||
}); | ||
spec.test('throws when trying to transferFrom more than allowed amount', async (ctx) => { | ||
@@ -453,0 +677,0 @@ const token = ctx.get('token'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
666584
10784
52
1