From 8e640fbe89b8ca178dec0f350039907e06d42077 Mon Sep 17 00:00:00 2001 From: Isaac Kang Date: Tue, 22 May 2018 18:54:19 -0400 Subject: [PATCH 1/4] cleanup, add comments & test --- test/eip20/eip20Factory.js | 52 ++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/test/eip20/eip20Factory.js b/test/eip20/eip20Factory.js index 357b3924..76fc3ffe 100644 --- a/test/eip20/eip20Factory.js +++ b/test/eip20/eip20Factory.js @@ -1,11 +1,53 @@ const EIP20Factory = artifacts.require('EIP20Factory'); contract('EIP20Factory', (accounts) => { - it('Verify a Human Standard Token once deployed using both verification functions.', async () => { + it('Verify an EIP20 token once deployed using both verification functions.', async () => { + const initialAmount = 100000; + const name = 'Simon Bucks'; + const decimals = 2; + const symbol = 'SBX'; + const args = [initialAmount, name, decimals, symbol, { from: accounts[0] }]; + + // new instance + const factory = await EIP20Factory.new(); + + // simulate: factory create a new EIP20 token + const newTokenAddr = await factory.createEIP20.call(...args); + + // tx: factory create a new EIP20 token + await factory.createEIP20(...args); + + // verify: new token's bytecode === EIP20's bytecode + const result = await factory.verifyEIP20.call(newTokenAddr, { from: accounts[0] }); + assert.strictEqual(result, true, 'the bytecode at newTokenAddr ' + + 'was not the same as the bytecode of an EIP20 token'); + + const isEIP20 = await factory.isEIP20.call(newTokenAddr); + assert.strictEqual(isEIP20, true, 'is not eip20'); + }); + + it('should verify that the `created` mapping includes a newly created token', async () => { + const initialAmount = 1000000; + const name = 'Maurelian Moolah'; + const decimals = 3; + const symbol = 'MOO'; + const args = [initialAmount, name, decimals, symbol, { from: accounts[0] }]; + + // new instance const factory = await EIP20Factory.new(); - const newTokenAddr = await factory.createEIP20.call(100000, 'Simon Bucks', 2, 'SBX', { from: accounts[0] }); - await factory.createEIP20(100000, 'Simon Bucks', 2, 'SBX', { from: accounts[0] }); - const res = await factory.verifyEIP20.call(newTokenAddr, { from: accounts[0] }); - assert(res, 'Could not verify the token.'); + + // simulate: factory create a new EIP20 token + const newTokenAddr = await factory.createEIP20.call(...args); + + // tx: factory create a new EIP20 token + await factory.createEIP20(...args); + + // verify: created mapping at index 1 is the newly deployed token + const result = await factory.created.call(accounts[0], 1); + assert.strictEqual( + result, + newTokenAddr, + 'the `created` mapping does not include the expected token', + ); }); }); From f2f4e46e9be6b2d335fd5210d670e93b2aa60cf5 Mon Sep 17 00:00:00 2001 From: Isaac Kang Date: Wed, 23 May 2018 11:08:34 -0400 Subject: [PATCH 2/4] add factory bytecode tests --- test/eip20/eip20Factory.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/eip20/eip20Factory.js b/test/eip20/eip20Factory.js index 76fc3ffe..bbff0add 100644 --- a/test/eip20/eip20Factory.js +++ b/test/eip20/eip20Factory.js @@ -1,4 +1,5 @@ const EIP20Factory = artifacts.require('EIP20Factory'); +const EIP20Bytecode = '0x6060604052341561000f57600080fd5b604051610dd1380380610dd18339810160405280805190602001909190805182019190602001805190602001909190805182019190505083600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508360008190555082600390805190602001906100a79291906100e3565b5081600460006101000a81548160ff021916908360ff16021790555080600590805190602001906100d99291906100e3565b5050505050610188565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061012457805160ff1916838001178555610152565b82800160010185558215610152579182015b82811115610151578251825591602001919060010190610136565b5b50905061015f9190610163565b5090565b61018591905b80821115610181576000816000905550600101610169565b5090565b90565b610c3a806101976000396000f3006060604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100b4578063095ea7b31461014257806318160ddd1461019c57806323b872dd146101c557806327e235e31461023e578063313ce5671461028b5780635c658165146102ba57806370a082311461032657806395d89b4114610373578063a9059cbb14610401578063dd62ed3e1461045b575b600080fd5b34156100bf57600080fd5b6100c76104c7565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101075780820151818401526020810190506100ec565b50505050905090810190601f1680156101345780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561014d57600080fd5b610182600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610565565b604051808215151515815260200191505060405180910390f35b34156101a757600080fd5b6101af610657565b6040518082815260200191505060405180910390f35b34156101d057600080fd5b610224600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190505061065d565b604051808215151515815260200191505060405180910390f35b341561024957600080fd5b610275600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506108f7565b6040518082815260200191505060405180910390f35b341561029657600080fd5b61029e61090f565b604051808260ff1660ff16815260200191505060405180910390f35b34156102c557600080fd5b610310600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610922565b6040518082815260200191505060405180910390f35b341561033157600080fd5b61035d600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610947565b6040518082815260200191505060405180910390f35b341561037e57600080fd5b610386610990565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103c65780820151818401526020810190506103ab565b50505050905090810190601f1680156103f35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561040c57600080fd5b610441600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610a2e565b604051808215151515815260200191505060405180910390f35b341561046657600080fd5b6104b1600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610b87565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561055d5780601f106105325761010080835404028352916020019161055d565b820191906000526020600020905b81548152906001019060200180831161054057829003601f168201915b505050505081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60005481565b600080600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015801561072e5750828110155b151561073957600080fd5b82600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555082600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8110156108865782600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055505b8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a360019150509392505050565b60016020528060005260406000206000915090505481565b600460009054906101000a900460ff1681565b6002602052816000526040600020602052806000526040600020600091509150505481565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a265780601f106109fb57610100808354040283529160200191610a26565b820191906000526020600020905b815481529060010190602001808311610a0957829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410151515610a7e57600080fd5b81600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050929150505600a165627a7a72305820fe8b20991003f12bfb732c4c823019deef9db7be83d3cbcab7017f09d91fe2570029'; contract('EIP20Factory', (accounts) => { it('Verify an EIP20 token once deployed using both verification functions.', async () => { @@ -50,4 +51,37 @@ contract('EIP20Factory', (accounts) => { 'the `created` mapping does not include the expected token', ); }); + + it('should return true if given a contract address with the same bytecode', async () => { + const factory = await EIP20Factory.new(); + + // deploy contract using correct eip20 bytecode + const txHash = await web3.eth.sendTransaction({ + from: accounts[0], + gas: 4700000, + gasPrice: 100000000000, + data: EIP20Bytecode, + }); + + const { contractAddress } = await web3.eth.getTransactionReceipt(txHash); + const result = await factory.verifyEIP20.call(contractAddress); + assert.strictEqual(result, true, 'should have returned true because the bytecode was exact'); + }); + + it('should return false when given a contract address with a modified bytecode', async () => { + const factory = await EIP20Factory.new(); + + // deploy contract using modified eip20 bytecode + const modifiedBytecode = EIP20Bytecode.slice(0, -10).concat('1234567890'); + const txHash = await web3.eth.sendTransaction({ + from: accounts[0], + gas: 4700000, + gasPrice: 100000000000, + data: modifiedBytecode, + }); + + const { contractAddress } = await web3.eth.getTransactionReceipt(txHash); + const result = await factory.verifyEIP20.call(contractAddress); + assert.strictEqual(result, false, 'should have returned false because the bytecode was not exact'); + }); }); From e02919fac6ea053fe9b0fc26e86e4dbcd01523cd Mon Sep 17 00:00:00 2001 From: Isaac Kang Date: Wed, 23 May 2018 11:08:50 -0400 Subject: [PATCH 3/4] add link to ethpm --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 268cca9c..bcc900cc 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ npm run compile ## Tests The repo has a comprehensive test suite. You can run it with `npm run test`. -## ethpm -The contracts in this repo are published under `tokens` on EPM. EPM is the recommended means of consuming token contracts in this repo. Copy-pasting code is highly discouraged. +## Ethereum Package Management (ethpm) +The contracts in this repo are published under `tokens` on [EPM](https://www.ethpm.com/registry/packages). EPM is the recommended means of consuming token contracts in this repo. Copy-pasting code is highly discouraged. ## Contributing Pull requests are welcome! Please keep standards discussions to the EIP repos. From ca0fd8b765fe68e955c94e54b5fe48523d7951ed Mon Sep 17 00:00:00 2001 From: Isaac Kang Date: Wed, 20 Jun 2018 18:31:54 -0400 Subject: [PATCH 4/4] use artifact bytecode, add comment --- test/eip20/eip20Factory.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/eip20/eip20Factory.js b/test/eip20/eip20Factory.js index bbff0add..ffc237e4 100644 --- a/test/eip20/eip20Factory.js +++ b/test/eip20/eip20Factory.js @@ -1,5 +1,5 @@ const EIP20Factory = artifacts.require('EIP20Factory'); -const EIP20Bytecode = '0x6060604052341561000f57600080fd5b604051610dd1380380610dd18339810160405280805190602001909190805182019190602001805190602001909190805182019190505083600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508360008190555082600390805190602001906100a79291906100e3565b5081600460006101000a81548160ff021916908360ff16021790555080600590805190602001906100d99291906100e3565b5050505050610188565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061012457805160ff1916838001178555610152565b82800160010185558215610152579182015b82811115610151578251825591602001919060010190610136565b5b50905061015f9190610163565b5090565b61018591905b80821115610181576000816000905550600101610169565b5090565b90565b610c3a806101976000396000f3006060604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100b4578063095ea7b31461014257806318160ddd1461019c57806323b872dd146101c557806327e235e31461023e578063313ce5671461028b5780635c658165146102ba57806370a082311461032657806395d89b4114610373578063a9059cbb14610401578063dd62ed3e1461045b575b600080fd5b34156100bf57600080fd5b6100c76104c7565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101075780820151818401526020810190506100ec565b50505050905090810190601f1680156101345780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561014d57600080fd5b610182600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610565565b604051808215151515815260200191505060405180910390f35b34156101a757600080fd5b6101af610657565b6040518082815260200191505060405180910390f35b34156101d057600080fd5b610224600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190505061065d565b604051808215151515815260200191505060405180910390f35b341561024957600080fd5b610275600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506108f7565b6040518082815260200191505060405180910390f35b341561029657600080fd5b61029e61090f565b604051808260ff1660ff16815260200191505060405180910390f35b34156102c557600080fd5b610310600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610922565b6040518082815260200191505060405180910390f35b341561033157600080fd5b61035d600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610947565b6040518082815260200191505060405180910390f35b341561037e57600080fd5b610386610990565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103c65780820151818401526020810190506103ab565b50505050905090810190601f1680156103f35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561040c57600080fd5b610441600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610a2e565b604051808215151515815260200191505060405180910390f35b341561046657600080fd5b6104b1600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610b87565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561055d5780601f106105325761010080835404028352916020019161055d565b820191906000526020600020905b81548152906001019060200180831161054057829003601f168201915b505050505081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60005481565b600080600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015801561072e5750828110155b151561073957600080fd5b82600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555082600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8110156108865782600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055505b8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a360019150509392505050565b60016020528060005260406000206000915090505481565b600460009054906101000a900460ff1681565b6002602052816000526040600020602052806000526040600020600091509150505481565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a265780601f106109fb57610100808354040283529160200191610a26565b820191906000526020600020905b815481529060010190602001808311610a0957829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410151515610a7e57600080fd5b81600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050929150505600a165627a7a72305820fe8b20991003f12bfb732c4c823019deef9db7be83d3cbcab7017f09d91fe2570029'; +const EIP20Bytecode = artifacts.require('EIP20').bytecode; contract('EIP20Factory', (accounts) => { it('Verify an EIP20 token once deployed using both verification functions.', async () => { @@ -23,6 +23,7 @@ contract('EIP20Factory', (accounts) => { assert.strictEqual(result, true, 'the bytecode at newTokenAddr ' + 'was not the same as the bytecode of an EIP20 token'); + // verify: new token's address is listed in the `isEIP20` mapping const isEIP20 = await factory.isEIP20.call(newTokenAddr); assert.strictEqual(isEIP20, true, 'is not eip20'); });