diff --git a/app/components/accountlist.js b/app/components/accountList.js similarity index 100% rename from app/components/accountlist.js rename to app/components/accountList.js diff --git a/config/blockchain.js b/config/blockchain.js new file mode 100644 index 0000000..322754e --- /dev/null +++ b/config/blockchain.js @@ -0,0 +1,62 @@ +module.exports = { + development: { + enabled: true, + networkType: "custom", // Can be: testnet, rinkeby, livenet or custom, in which case, it will use the specified networkId + networkId: "1337", // Network id used when networkType is custom + isDev: true, // Uses and ephemeral proof-of-authority network with a pre-funded developer account, mining enabled + genesisBlock: "config/development/genesis.json", // Genesis block to initiate on first creation of a development node + datadir: ".embark/development/datadir", // Data directory for the databases and keystore + mineWhenNeeded: true, // Uses our custom script (if isDev is false) to mine only when needed + nodiscover: true, // Disables the peer discovery mechanism (manual peer addition) + maxpeers: 0, // Maximum number of network peers (network disabled if set to 0) (default: 25) + rpcHost: "localhost", // HTTP-RPC server listening interface (default: "localhost") + rpcPort: 8545, // HTTP-RPC server listening port (default: 8545) + rpcCorsDomain: "auto", // Comma separated list of domains from which to accept cross origin requests (browser enforced) + // When set to "auto", Embark will automatically set the cors to the address of the webserver + proxy: true, // Proxy is used to present meaningful information about transactions + account: { + // "address": "", // When specified, uses that address instead of the default one for the network + password: "config/development/password" // Password to unlock the account + }, + targetGasLimit: 8000000, // Target gas limit sets the artificial target gas floor for the blocks to mine + wsRPC: true, // Enable the WS-RPC server + wsOrigins: "auto", // Origins from which to accept websockets requests + // When set to "auto", Embark will automatically set the cors to the address of the webserver + wsHost: "localhost", // WS-RPC server listening interface (default: "localhost") + wsPort: 8546, // WS-RPC server listening port (default: 8546) + simulatorMnemonic: "example exile argue silk regular smile grass bomb merge arm assist farm", // Mnemonic used by the simulator to generate a wallet + simulatorBlocktime: 0 // Specify blockTime in seconds for automatic mining. Default is 0 and no auto-mining. + }, + testnet: { + enabled: true, + networkType: "testnet", + light: true, + rpcHost: "localhost", + rpcPort: 8545, + rpcCorsDomain: "http://localhost:8000", + account: { + password: "config/testnet/password" + } + }, + livenet: { + enabled: true, + networkType: "livenet", + light: true, + rpcHost: "localhost", + rpcPort: 8545, + rpcCorsDomain: "http://localhost:8000", + account: { + password: "config/livenet/password" + } + }, + privatenet: { + enabled: true, + networkType: "custom", + rpcHost: "localhost", + rpcPort: 8545, + rpcCorsDomain: "http://localhost:8000", + datadir: "yourdatadir", + networkId: "123", + bootnodes: "" + } +}; diff --git a/config/blockchain.json b/config/blockchain.json deleted file mode 100644 index 3e17281..0000000 --- a/config/blockchain.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "development": { - "enabled": true, - "networkType": "custom", - "genesisBlock": "config/development/genesis.json", - "datadir": ".embark/development/datadir", - "mineWhenNeeded": true, - "nodiscover": true, - "maxpeers": 0, - "rpcHost": "localhost", - "rpcPort": 8545, - "rpcCorsDomain": "auto", - "account": { - "password": "config/development/password" - }, - "targetGasLimit": 8000000, - "wsOrigins": "auto", - "wsRPC": true, - "wsHost": "localhost", - "wsPort": 8546, - "simulatorMnemonic": "example exile argue silk regular smile grass bomb merge arm assist farm", - "simulatorBlocktime": 0 - }, - "testnet": { - "enabled": true, - "networkType": "testnet", - "syncMode": "light", - "rpcHost": "localhost", - "rpcPort": 8545, - "rpcCorsDomain": "http://localhost:8000", - "account": { - "password": "config/testnet/password" - } - }, - "livenet": { - "enabled": true, - "networkType": "livenet", - "syncMode": "light", - "rpcHost": "localhost", - "rpcPort": 8545, - "rpcCorsDomain": "http://localhost:8000", - "account": { - "password": "config/livenet/password" - } - }, - "privatenet": { - "enabled": true, - "networkType": "custom", - "rpcHost": "localhost", - "rpcPort": 8545, - "rpcCorsDomain": "http://localhost:8000", - "datadir": "yourdatadir", - "networkId": "123", - "bootnodes": "" - } -} diff --git a/config/communication.js b/config/communication.js new file mode 100644 index 0000000..8c4d1f9 --- /dev/null +++ b/config/communication.js @@ -0,0 +1,12 @@ +module.exports = { + default: { + enabled: true, + provider: "whisper", // Communication provider. Currently, Embark only supports whisper + available_providers: ["whisper"], // Array of available providers + connection: { + host: "localhost", // Host of the blockchain node + port: 8546, // Port of the blockchain node + type: "ws" // Type of connection (ws or rpc) + } + } +}; diff --git a/config/communication.json b/config/communication.json deleted file mode 100644 index 80ec2f8..0000000 --- a/config/communication.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "default": { - "enabled": true, - "provider": "whisper", - "available_providers": ["whisper", "orbit"], - "connection": { - "host": "localhost", - "port": 8546, - "type": "ws" - } - } -} diff --git a/config/namesystem.js b/config/namesystem.js new file mode 100644 index 0000000..10e20d6 --- /dev/null +++ b/config/namesystem.js @@ -0,0 +1,6 @@ +module.exports = { + default: { + available_providers: ["ens"], + provider: "ens" + } +}; diff --git a/config/storage.js b/config/storage.js new file mode 100644 index 0000000..59ef12b --- /dev/null +++ b/config/storage.js @@ -0,0 +1,35 @@ +module.exports = { + default: { + enabled: true, + ipfs_bin: "ipfs", + provider: "ipfs", + available_providers: ["ipfs"], + upload: { + host: "localhost", + port: 5001 + }, + dappConnection: [ + { + provider:"ipfs", + host: "localhost", + port: 5001, + getUrl: "http://localhost:8080/ipfs/" + } + ] + // Configuration to start Swarm in the same terminal as `embark run` + /*,account: { + address: "YOUR_ACCOUNT_ADDRESS", // Address of account accessing Swarm + password: "PATH/TO/PASSWORD/FILE" // File containing the password of the account + }, + swarmPath: "PATH/TO/SWARM/EXECUTABLE" // Path to swarm executable (default: swarm)*/ + }, + development: { + enabled: true, + provider: "ipfs", + upload: { + host: "localhost", + port: 5001, + getUrl: "http://localhost:8080/ipfs/" + } + } +}; diff --git a/config/storage.json b/config/storage.json deleted file mode 100644 index e964285..0000000 --- a/config/storage.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "default": { - "versions": { - "ipfs-api": "17.2.4" - }, - "enabled": false, - "ipfs_bin": "ipfs", - "provider": "ipfs", - "available_providers": ["ipfs"], - "upload":{ - "provider": "ipfs", - "host": "ipfs.infura.io", - "port": 5001, - "protocol": "https", - "getUrl": "https://ipfs.infura.io/ipfs" - } - }, - "development": { - "enabled": true, - "provider": "ipfs", - "host": "localhost", - "port": 5001, - "getUrl": "https://localhost:8080/ipfs/" - } -} diff --git a/config/webserver.js b/config/webserver.js new file mode 100644 index 0000000..1814065 --- /dev/null +++ b/config/webserver.js @@ -0,0 +1,5 @@ +module.exports = { + enabled: true, + host: "localhost", + port: 8000 +}; diff --git a/config/webserver.json b/config/webserver.json deleted file mode 100644 index c28a311..0000000 --- a/config/webserver.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "enabled": true, - "host": "localhost", - "port": 8000 -} diff --git a/contracts/common/MessageSigned.sol b/contracts/common/MessageSigned.sol index 5a5a262..95d2f14 100644 --- a/contracts/common/MessageSigned.sol +++ b/contracts/common/MessageSigned.sol @@ -46,7 +46,7 @@ contract MessageSigned { internal returns (bytes32 signHash) { - signHash = keccak256("\x19Ethereum Signed Message:\n32", _hash); + signHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", _hash)); } /** diff --git a/contracts/token/StandardToken.sol b/contracts/token/StandardToken.sol index 826984b..3d61313 100644 --- a/contracts/token/StandardToken.sol +++ b/contracts/token/StandardToken.sol @@ -112,7 +112,11 @@ contract StandardToken is ERC20Token { { if (balances[_from] >= _value && _value > 0) { balances[_from] -= _value; - balances[_to] += _value; + if(_to == address(0)) { + supply -= _value; + } else { + balances[_to] += _value; + } emit Transfer(_from, _to, _value); return true; } else { diff --git a/test/abstract/controlled.js b/test/abstract/controlled.js new file mode 100644 index 0000000..95e0197 --- /dev/null +++ b/test/abstract/controlled.js @@ -0,0 +1,31 @@ + +exports.Test = (Controlled) => { + describe("Controlled", async function() { + this.timeout(0); + var accounts; + before(function(done) { + web3.eth.getAccounts().then(function (res) { + accounts = res; + done(); + }); + }); + + + it("should start with msg.sender as controller", async function() { + var controller = await Controlled.methods.controller().call(); + assert(controller, accounts[0]); + }); + + it("should allow controller to set new controller", async function() { + await Controlled.methods.changeController(accounts[1]).send({from: accounts[0]}); + var controller = await Controlled.methods.controller().call(); + assert(controller, accounts[1]); + }); + + it("should set back to original controller", async function() { + await Controlled.methods.changeController(accounts[0]).send({from: accounts[1]}); + var controller = await Controlled.methods.controller().call(); + assert(controller, accounts[0]); + }); + }); +} \ No newline at end of file diff --git a/test/abstract/erc20tokenspec.js b/test/abstract/erc20tokenspec.js new file mode 100644 index 0000000..e5f0637 --- /dev/null +++ b/test/abstract/erc20tokenspec.js @@ -0,0 +1,85 @@ + +const ERC20Receiver = require('Embark/contracts/ERC20Receiver'); + +exports.config = { + contracts : { + "ERC20Receiver": { + } + } +} + +exports.Test = (ERC20Token) => { + describe("ERC20Token", function() { + + var accounts; + before(function(done) { + web3.eth.getAccounts().then(function (res) { + accounts = res; + done(); + }); + }); + + it("should transfer 1 token", async function() { + let initialBalance0 = await ERC20Token.methods.balanceOf(accounts[0]).call(); + let initialBalance1 = await ERC20Token.methods.balanceOf(accounts[1]).call(); + await ERC20Token.methods.transfer(accounts[1],1).send({from: accounts[0]}); + let result0 = await ERC20Token.methods.balanceOf(accounts[0]).call(); + let result1 = await ERC20Token.methods.balanceOf(accounts[1]).call(); + + assert.equal(result0, +initialBalance0-1, "account 0 balance unexpected"); + assert.equal(result1, +initialBalance1+1, "account 1 balance unexpected"); + }); + + it("should set approved amount", async function() { + await ERC20Token.methods.approve(accounts[2],10000000).send({from: accounts[0]}); + let result = await ERC20Token.methods.allowance(accounts[0], accounts[2]).call(); + assert.equal(result, 10000000); + }); + + it("should consume allowance amount", async function() { + let initialAllowance = await ERC20Token.methods.allowance(accounts[0], accounts[2]).call(); + await ERC20Token.methods.transferFrom(accounts[0], accounts[0],1).send({from: accounts[2]}); + let result = await ERC20Token.methods.allowance(accounts[0], accounts[2]).call(); + + assert.equal(result, +initialAllowance-1); + }); + + it("should transfer approved amount", async function() { + let initialBalance0 = await ERC20Token.methods.balanceOf(accounts[0]).call(); + let initialBalance1 = await ERC20Token.methods.balanceOf(accounts[1]).call(); + await ERC20Token.methods.transferFrom(accounts[0], accounts[1],1).send({from: accounts[2]}); + let result0 = await ERC20Token.methods.balanceOf(accounts[0]).call(); + let result1 = await ERC20Token.methods.balanceOf(accounts[1]).call(); + + assert.equal(result0, +initialBalance0-1); + assert.equal(result1, +initialBalance1+1); + }); + + + it("should unset approved amount", async function() { + await ERC20Token.methods.approve(accounts[2],0).send({from: accounts[0]}); + let result = await ERC20Token.methods.allowance(accounts[0], accounts[2]).call(); + assert.equal(result, 0); + }); + + it("should deposit approved amount to contract ERC20Receiver", async function() { + //ERC20Receiver = await ERC20Receiver.deploy().send(); + //console.log(ERC20Receiver.address); + await ERC20Token.methods.approve(ERC20Receiver.address, 10).send({from: accounts[0]}); + await ERC20Receiver.methods.depositToken(ERC20Token.address, 10).send({from: accounts[0]}); + let result = await ERC20Receiver.methods.tokenBalanceOf(ERC20Token.address, accounts[0]).call(); + assert.equal(result, 10, "ERC20Receiver.tokenBalanceOf("+ERC20Token.address+","+accounts[0]+") wrong"); + }); + + it("should witdraw approved amount from contract ERC20Receiver", async function() { + let tokenBalance = await ERC20Receiver.methods.tokenBalanceOf(ERC20Token.address, accounts[0]).call(); + await ERC20Receiver.methods.withdrawToken(ERC20Token.address, tokenBalance).send({from: accounts[0]}); + tokenBalance = await ERC20Receiver.methods.tokenBalanceOf(ERC20Token.address, accounts[0]).call(); + assert.equal(tokenBalance, 0, "ERC20Receiver.tokenBalanceOf("+ERC20Token.address+","+accounts[0]+") wrong"); + }); + + //TODO: include checks for expected events fired + + + }); +} \ No newline at end of file diff --git a/test/controlled.js b/test/controlled.js deleted file mode 100644 index 5d98ed2..0000000 --- a/test/controlled.js +++ /dev/null @@ -1,29 +0,0 @@ - -exports.Test = (contractsConfig, afterDeploy) => { - - describe("Controlled", async function() { - this.timeout(0); - var Controlled; - var accountsArr; - before(function(done) { - config(contractsConfig, async function(accounts) { - Controlled = Contract; - accountsArr = accounts; - await afterDeploy(accounts, Contract); - done() - }); - }); - - - it("should start with msg.sender as controller", async function() { - var controller = await Controlled.methods.controller().call(); - assert(controller, accountsArr[0]); - }); - - it("should allow controller to set new controller", async function() { - await Controlled.methods.changeController(accountsArr[1]).send({from: accountsArr[0]}); - var controller = await Controlled.methods.controller().call(); - assert(controller, accountsArr[1]); - }); - }); -} diff --git a/test/ensregistry.js b/test/ensregistry.js index 1f60e3b..74a1be7 100644 --- a/test/ensregistry.js +++ b/test/ensregistry.js @@ -1,33 +1,35 @@ const utils = require('../utils/testUtils.js'); +const ENSRegistry = require('Embark/contracts/ENSRegistry'); const web3Utils = require('web3-utils'); const namehash = require('eth-ens-namehash'); +config({ + contracts: { + "ENSRegistry": { }, + } +}); + contract('ENS', function () { this.timeout(0); - let ens; let accountsArr; before(function(done) { - var contractsConfig = { - "ENSRegistry": { }, - }; - config(contractsConfig, function(accounts) { - ens = ENSRegistry; - accountsArr = accounts; - done() + web3.eth.getAccounts().then(function (res) { + accountsArr = res; + done(); }); - }); + }); it('should allow ownership transfers', async () => { - let result = await ens.methods.setOwner(utils.zeroBytes32, accountsArr[1]).send({from: accountsArr[0]}); - assert.equal(await ens.methods.owner(utils.zeroBytes32).call(), accountsArr[1]) + let result = await ENSRegistry.methods.setOwner(utils.zeroBytes32, accountsArr[1]).send({from: accountsArr[0]}); + assert.equal(await ENSRegistry.methods.owner(utils.zeroBytes32).call(), accountsArr[1]) assert.equal(result.events.Transfer.returnValues.node, utils.zeroBytes32); assert.equal(result.events.Transfer.returnValues.owner, accountsArr[1]); }); it('should prohibit transfers by non-owners', async () => { try { - await ens.methods.setOwner(utils.zeroBytes32, accountsArr[2]).send({from: accountsArr[0]}); + await ENSRegistry.methods.setOwner(utils.zeroBytes32, accountsArr[2]).send({from: accountsArr[0]}); } catch (error) { return utils.ensureException(error); } @@ -36,16 +38,16 @@ contract('ENS', function () { }); it('should allow setting resolvers', async () => { - let result = await ens.methods.setResolver(utils.zeroBytes32, accountsArr[3]).send({from: accountsArr[1]}); + let result = await ENSRegistry.methods.setResolver(utils.zeroBytes32, accountsArr[3]).send({from: accountsArr[1]}); let args = result.events.NewResolver.returnValues; assert.equal(args.node, utils.zeroBytes32); assert.equal(args.resolver, accountsArr[3]); - assert.equal(await ens.methods.resolver(utils.zeroBytes32).call(), accountsArr[3]); + assert.equal(await ENSRegistry.methods.resolver(utils.zeroBytes32).call(), accountsArr[3]); }); it('should prevent setting resolvers by non-owners', async () => { try { - await ens.methods.setResolver(utils.zeroBytes32, accountsArr[4]).send({from: accountsArr[0]}); + await ENSRegistry.methods.setResolver(utils.zeroBytes32, accountsArr[4]).send({from: accountsArr[0]}); } catch (error) { return utils.ensureException(error); } @@ -54,8 +56,8 @@ contract('ENS', function () { }); it('should allow setting the TTL', async () => { - let result = await ens.methods.setTTL(utils.zeroBytes32, 3600).send({from: accountsArr[1]}); - assert.equal(await ens.methods.ttl(utils.zeroBytes32).call(), 3600); + let result = await ENSRegistry.methods.setTTL(utils.zeroBytes32, 3600).send({from: accountsArr[1]}); + assert.equal(await ENSRegistry.methods.ttl(utils.zeroBytes32).call(), 3600); let args = result.events.NewTTL.returnValues; assert.equal(args.node, utils.zeroBytes32); assert.equal(args.ttl, 3600); @@ -63,7 +65,7 @@ contract('ENS', function () { it('should prevent setting the TTL by non-owners', async () => { try { - await ens.methods.setTTL(utils.zeroBytes32, 1200).send({from: accountsArr[0]}); + await ENSRegistry.methods.setTTL(utils.zeroBytes32, 1200).send({from: accountsArr[0]}); } catch (error) { return utils.ensureException(error); } @@ -72,8 +74,8 @@ contract('ENS', function () { }); it('should allow the creation of subnodes', async () => { - let result = await ens.methods.setSubnodeOwner(utils.zeroBytes32, web3Utils.sha3('eth'), accountsArr[2]).send({from: accountsArr[1]}); - assert.equal(await ens.methods.owner(namehash.hash('eth')).call(), accountsArr[2]); + let result = await ENSRegistry.methods.setSubnodeOwner(utils.zeroBytes32, web3Utils.sha3('eth'), accountsArr[2]).send({from: accountsArr[1]}); + assert.equal(await ENSRegistry.methods.owner(namehash.hash('eth')).call(), accountsArr[2]); let args = result.events.NewOwner.returnValues; assert.equal(args.node, utils.zeroBytes32); assert.equal(args.label, web3Utils.sha3('eth')); @@ -82,7 +84,7 @@ contract('ENS', function () { it('should prohibit subnode creation by non-owners', async () => { try { - await ens.methods.setSubnodeOwner(utils.zeroBytes32, web3Utils.sha3('eth'), accountsArr[3]).send({from: accountsArr[0]}); + await ENSRegistry.methods.setSubnodeOwner(utils.zeroBytes32, web3Utils.sha3('eth'), accountsArr[3]).send({from: accountsArr[0]}); } catch (error) { return utils.ensureException(error); } diff --git a/test/erc20token.js b/test/erc20token.js deleted file mode 100644 index 6889734..0000000 --- a/test/erc20token.js +++ /dev/null @@ -1,78 +0,0 @@ - -exports.Test = (contractsConfig, afterDeploy) => { - describe("ERC20Token", async function() { - this.timeout(0); - var ERC20Token; - var accountsArr; - before(function(done) { - contractsConfig["ERC20Receiver"] = {}; - EmbarkSpec.deployAll(contractsConfig, async function(accounts) { - ERC20Token = Contract; - accountsArr = accounts; - await afterDeploy(accounts, Contract); - done() - }); - }); - - it("should transfer 1 token", async function() { - let initialBalance0 = await ERC20Token.methods.balanceOf(accountsArr[0]).call(); - let initialBalance1 = await ERC20Token.methods.balanceOf(accountsArr[1]).call(); - await ERC20Token.methods.transfer(accountsArr[1],1).send({from: accountsArr[0]}); - let result0 = await ERC20Token.methods.balanceOf(accountsArr[0]).call(); - let result1 = await ERC20Token.methods.balanceOf(accountsArr[1]).call(); - - assert.equal(result0, +initialBalance0-1, "account 0 balance unexpected"); - assert.equal(result1, +initialBalance1+1, "account 1 balance unexpected"); - }); - - it("should set approved amount", async function() { - await ERC20Token.methods.approve(accountsArr[2],10000000).send({from: accountsArr[0]}); - let result = await ERC20Token.methods.allowance(accountsArr[0], accountsArr[2]).call(); - assert.equal(result, 10000000); - }); - - it("should consume allowance amount", async function() { - let initialAllowance = await ERC20Token.methods.allowance(accountsArr[0], accountsArr[2]).call(); - await ERC20Token.methods.transferFrom(accountsArr[0], accountsArr[0],1).send({from: accountsArr[2]}); - let result = await ERC20Token.methods.allowance(accountsArr[0], accountsArr[2]).call(); - - assert.equal(result, +initialAllowance-1); - }); - - it("should transfer approved amount", async function() { - let initialBalance0 = await ERC20Token.methods.balanceOf(accountsArr[0]).call(); - let initialBalance1 = await ERC20Token.methods.balanceOf(accountsArr[1]).call(); - await ERC20Token.methods.transferFrom(accountsArr[0], accountsArr[1],1).send({from: accountsArr[2]}); - let result0 = await ERC20Token.methods.balanceOf(accountsArr[0]).call(); - let result1 = await ERC20Token.methods.balanceOf(accountsArr[1]).call(); - - assert.equal(result0, +initialBalance0-1); - assert.equal(result1, +initialBalance1+1); - }); - - - it("should unset approved amount", async function() { - await ERC20Token.methods.approve(accountsArr[2],0).send({from: accountsArr[0]}); - let result = await ERC20Token.methods.allowance(accountsArr[0], accountsArr[2]).call(); - assert.equal(result, 0); - }); - - it("should deposit approved amount to contract ERC20Receiver", async function() { - await ERC20Token.methods.approve(ERC20Receiver.address,10).send({from: accountsArr[0]}); - await ERC20Receiver.methods.depositToken(ERC20Token.address).send({from: accountsArr[0]}); - let result = await ERC20Receiver.methods.tokenBalanceOf(ERC20Token.address, accountsArr[0]).call(); - assert.equal(result, 10, "ERC20Receiver.tokenBalanceOf("+ERC20Token.address+","+accountsArr[0]+") wrong"); - }); - - it("should witdraw approved amount from contract ERC20Receiver", async function() { - let tokenBalance = await ERC20Receiver.methods.tokenBalanceOf(ERC20Token.address, accountsArr[0]).call(); - await ERC20Receiver.methods.withdrawToken(ERC20Token.address, tokenBalance).send({from: accountsArr[0]}); - tokenBalance = await ERC20Receiver.methods.tokenBalanceOf(ERC20Token.address, accountsArr[0]).call(); - assert.equal(tokenBalance, 0, "ERC20Receiver.tokenBalanceOf("+ERC20Token.address+","+accountsArr[0]+") wrong"); - }); - - //TODO: include checks for expected events fired - - - }); -} \ No newline at end of file diff --git a/test/testtoken.js b/test/testtoken.js index 15fcd15..3e17461 100644 --- a/test/testtoken.js +++ b/test/testtoken.js @@ -1,39 +1,55 @@ -const ERC20Token = require('./erc20token'); +const Utils = require('../utils/testUtils'); +const TestToken = require('Embark/contracts/TestToken'); +const ERC20TokenSpec = require('./abstract/erc20tokenspec'); -describe("TestToken", async function() { - this.timeout(0); - var accountsArr; +config({ + contracts: { + "TestToken": { + }, + ...ERC20TokenSpec.config.contracts + } +}); +contract("TestToken", function() { + this.timeout(0); + var accounts; before(function(done) { - var contractsConfig = { - "TestToken": { - } - }; - EmbarkSpec.deployAll(contractsConfig, async function(accounts) { - accountsArr = accounts - done() + web3.eth.getAccounts().then(function (res) { + accounts = res; + done(); }); }); it("should increase totalSupply in mint", async function() { let initialSupply = await TestToken.methods.totalSupply().call(); - await TestToken.methods.mint(100).send({from: accountsArr[0]}); + await TestToken.methods.mint(100).send(); let result = await TestToken.methods.totalSupply().call(); assert.equal(result, +initialSupply+100); }); it("should increase accountBalance in mint", async function() { - let initialBalance = await TestToken.methods.balanceOf(accountsArr[0]).call(); - await TestToken.methods.mint(100).send({from: accountsArr[0]}); - let result = await TestToken.methods.balanceOf(accountsArr[0]).call(); + let initialBalance = await TestToken.methods.balanceOf(accounts[0]).call(); + await TestToken.methods.mint(100).send({from: accounts[0]}); + let result = await TestToken.methods.balanceOf(accounts[0]).call(); assert.equal(result, +initialBalance+100); }); - var erc20tokenConfig = { - "Contract": { "instanceOf" : "TestToken" } - } - ERC20Token.Test(erc20tokenConfig, async function (accounts, TestToken) { + + it("should burn account supply", async function() { + let initialBalance = await TestToken.methods.balanceOf(accounts[0]).call(); + await TestToken.methods.transfer(Utils.zeroAddress, initialBalance).send({from: accounts[0]}); + assert.equal(await TestToken.methods.totalSupply().call(), 0); + assert.equal(await TestToken.methods.balanceOf(accounts[0]).call(), 0); + }) + + it("should mint balances for ERC20TokenSpec", async function() { + let initialBalance = 7 * 10 ^ 18; for(i=0;i { - const username = reservedNames[5]; + const username = ReservedUsernames[5]; const usernameHash = namehash.hash(username + '.' + registry.registry); const registrant = accountsArr[1]; await TestToken.methods.mint(registry.price).send({from: registrant}); @@ -622,7 +622,7 @@ contract('UsernameRegistrar', function () { assert.equal(await ens.methods.owner(usernameHash).call(), registrant); let failed; try{ - await UsernameRegistrar.methods.slashReservedUsername(web3Utils.toHex(username), merkleTree.getHexProof(reservedNames[1])).send() + await UsernameRegistrar.methods.slashReservedUsername(web3Utils.toHex(username), merkleTree.getHexProof(ReservedUsernames[1])).send() failed = false; } catch(e){ failed = true; @@ -630,7 +630,7 @@ contract('UsernameRegistrar', function () { assert(failed, "Was slashed anyway"); }); it('should slash reserved name username', async () => { - const username = reservedNames[7]; + const username = ReservedUsernames[7]; const usernameHash = namehash.hash(username + '.' + registry.registry); const registrant = accountsArr[1]; await TestToken.methods.mint(registry.price).send({from: registrant});