Skip to content

Commit

Permalink
Updates 151 ENS Usernames to Embark 3.1 (#21)
Browse files Browse the repository at this point in the history
* fix run error

* transfer to zero should decerease supply (burn action)

* dont increment address 0 balance

* fix warning

* Update bootstrap to Embark 3.1 (#10)

* update configs to .js

* update tests

* better test abstraction

* undo changes after test

* small fixes
  • Loading branch information
3esmit authored Sep 5, 2018
1 parent eb55856 commit 50db6df
Show file tree
Hide file tree
Showing 19 changed files with 309 additions and 256 deletions.
File renamed without changes.
62 changes: 62 additions & 0 deletions config/blockchain.js
Original file line number Diff line number Diff line change
@@ -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: ""
}
};
56 changes: 0 additions & 56 deletions config/blockchain.json

This file was deleted.

12 changes: 12 additions & 0 deletions config/communication.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
};
12 changes: 0 additions & 12 deletions config/communication.json

This file was deleted.

6 changes: 6 additions & 0 deletions config/namesystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
default: {
available_providers: ["ens"],
provider: "ens"
}
};
35 changes: 35 additions & 0 deletions config/storage.js
Original file line number Diff line number Diff line change
@@ -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/"
}
}
};
25 changes: 0 additions & 25 deletions config/storage.json

This file was deleted.

5 changes: 5 additions & 0 deletions config/webserver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
enabled: true,
host: "localhost",
port: 8000
};
5 changes: 0 additions & 5 deletions config/webserver.json

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/common/MessageSigned.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
6 changes: 5 additions & 1 deletion contracts/token/StandardToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 31 additions & 0 deletions test/abstract/controlled.js
Original file line number Diff line number Diff line change
@@ -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]);
});
});
}
85 changes: 85 additions & 0 deletions test/abstract/erc20tokenspec.js
Original file line number Diff line number Diff line change
@@ -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


});
}
29 changes: 0 additions & 29 deletions test/controlled.js

This file was deleted.

Loading

0 comments on commit 50db6df

Please sign in to comment.