2020-02-19 15:47:59 +00:00
|
|
|
/*global artifacts, contract, config, it, web3, evmMethod*/
|
2018-06-01 14:48:29 +00:00
|
|
|
const assert = require('assert');
|
2020-01-24 11:04:42 +00:00
|
|
|
const AnotherStorage = artifacts.require('AnotherStorage');
|
|
|
|
const SimpleStorage = artifacts.require('SimpleStorage');
|
2018-06-01 14:48:29 +00:00
|
|
|
|
2019-10-17 18:39:25 +00:00
|
|
|
let accounts, defaultAccount;
|
2019-11-06 19:45:27 +00:00
|
|
|
const numAddresses = 10;
|
2018-06-06 20:43:08 +00:00
|
|
|
|
2018-06-01 14:48:29 +00:00
|
|
|
config({
|
2019-08-30 20:50:20 +00:00
|
|
|
blockchain: {
|
2018-06-06 19:33:48 +00:00
|
|
|
"accounts": [
|
|
|
|
{
|
2018-06-06 20:43:08 +00:00
|
|
|
"mnemonic": "example exile argue silk regular smile grass bomb merge arm assist farm",
|
2019-11-06 19:45:27 +00:00
|
|
|
balance: "5ether",
|
2020-02-14 13:31:26 +00:00
|
|
|
hdpath: "m/44'/1'/0'/0/",
|
2019-11-06 19:45:27 +00:00
|
|
|
numAddresses: 10
|
2018-06-06 19:33:48 +00:00
|
|
|
}
|
2018-07-31 10:01:52 +00:00
|
|
|
]
|
2018-06-06 19:33:48 +00:00
|
|
|
},
|
2018-06-01 14:48:29 +00:00
|
|
|
contracts: {
|
2019-08-30 20:50:20 +00:00
|
|
|
deploy: {
|
|
|
|
"SimpleStorage": {
|
|
|
|
args: [100]
|
|
|
|
},
|
|
|
|
"AnotherStorage": {
|
|
|
|
args: ["$SimpleStorage"]
|
|
|
|
}
|
2018-06-01 14:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-06 20:43:08 +00:00
|
|
|
}, (err, theAccounts) => {
|
|
|
|
accounts = theAccounts;
|
2019-10-17 18:39:25 +00:00
|
|
|
defaultAccount = accounts[0];
|
2018-06-01 14:48:29 +00:00
|
|
|
});
|
|
|
|
|
2019-10-22 13:27:22 +00:00
|
|
|
contract("AnotherStorage", function() {
|
2018-01-05 20:10:47 +00:00
|
|
|
this.timeout(0);
|
2017-02-10 00:38:02 +00:00
|
|
|
|
2019-06-13 16:54:52 +00:00
|
|
|
it("should have got the default account in the describe", function () {
|
|
|
|
assert.strictEqual(defaultAccount, accounts[0]);
|
|
|
|
});
|
|
|
|
|
2018-06-08 17:10:47 +00:00
|
|
|
it("should have account with balance", async function() {
|
2019-10-22 13:27:22 +00:00
|
|
|
const balance = await web3.eth.getBalance(accounts[0]);
|
2018-06-08 17:10:47 +00:00
|
|
|
assert.ok(parseInt(balance, 10) > 4900000000000000000);
|
|
|
|
assert.ok(parseInt(balance, 10) <= 5000000000000000000);
|
|
|
|
});
|
|
|
|
|
2019-11-06 19:45:27 +00:00
|
|
|
it("should have the right balance for all other accounts ", async function() {
|
|
|
|
let balance;
|
|
|
|
|
|
|
|
for (let i = 1; i < numAddresses - 3; i++) {
|
|
|
|
balance = await web3.eth.getBalance(accounts[i]);
|
|
|
|
assert.strictEqual(parseInt(balance, 10), 5000000000000000000, `Account ${i} doesn't have the balance set`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-17 18:48:31 +00:00
|
|
|
it("set SimpleStorage address", async function() {
|
|
|
|
let result = await AnotherStorage.methods.simpleStorageAddress().call();
|
|
|
|
assert.equal(result.toString(), SimpleStorage.options.address);
|
2017-02-10 00:38:02 +00:00
|
|
|
});
|
2018-06-06 20:43:08 +00:00
|
|
|
|
2018-06-10 16:11:34 +00:00
|
|
|
it("set SimpleStorage address with alternative syntax", async function() {
|
|
|
|
let result = await AnotherStorage.simpleStorageAddress();
|
|
|
|
assert.equal(result.toString(), SimpleStorage.options.address);
|
|
|
|
});
|
2020-02-19 15:47:59 +00:00
|
|
|
|
|
|
|
it("can sign using eth_signTypedData with a custom account", async function() {
|
|
|
|
const chainId = await web3.eth.net.getId();
|
|
|
|
|
|
|
|
const domain = [
|
|
|
|
{name: "name", type: "string"},
|
|
|
|
{name: "version", type: "string"},
|
|
|
|
{name: "chainId", type: "uint256"},
|
|
|
|
{name: "verifyingContract", type: "address"}
|
|
|
|
];
|
|
|
|
|
|
|
|
const redeem = [
|
|
|
|
{name: "keycard", type: "address"},
|
|
|
|
{name: "receiver", type: "address"},
|
|
|
|
{name: "code", type: "bytes32"}
|
|
|
|
];
|
|
|
|
|
|
|
|
const domainData = {
|
|
|
|
name: "KeycardGift",
|
|
|
|
version: "1",
|
|
|
|
chainId,
|
|
|
|
verifyingContract: SimpleStorage.options.address
|
|
|
|
};
|
|
|
|
|
|
|
|
const message = {
|
|
|
|
keycard: accounts[1],
|
|
|
|
receiver: accounts[2],
|
|
|
|
code: web3.utils.sha3("hello world")
|
|
|
|
};
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
types: {
|
|
|
|
EIP712Domain: domain,
|
|
|
|
Redeem: redeem
|
|
|
|
},
|
|
|
|
primaryType: "Redeem",
|
|
|
|
domain: domainData,
|
|
|
|
message
|
|
|
|
};
|
|
|
|
|
|
|
|
const signature = await evmMethod("eth_signTypedData", [
|
|
|
|
accounts[0],
|
|
|
|
data
|
|
|
|
]);
|
|
|
|
assert.strictEqual(signature, '0x5dcbab53809985222a62807dd2f23551902fa4471377e319d5d682e1458646714cc71' +
|
|
|
|
'faa76cf6de3e0d871edbfa85628db552619d681594d5af2f34be2c33cdd1b');
|
|
|
|
});
|
2017-02-10 00:38:02 +00:00
|
|
|
});
|