embark/dapps/tests/app/test/array_references_spec.js

90 lines
2.1 KiB
JavaScript
Raw Normal View History

/*global artifacts, contract, config, it, web3, evmMethod*/
2018-06-01 14:48:29 +00:00
const assert = require('assert');
const SomeContract = artifacts.require('SomeContract');
const MyToken2 = artifacts.require('MyToken2');
2018-06-01 14:48:29 +00:00
let accounts;
2018-06-01 14:48:29 +00:00
config({
contracts: {
deploy: {
"Token": {
deploy: false,
args: [1000]
},
"MyToken2": {
instanceOf: "Token",
args: [2000]
},
"SomeContract": {
"args": [
["$MyToken2", "$accounts[0]"],
100
]
}
2018-06-01 14:48:29 +00:00
}
}
}, (err, theAccounts) => {
accounts = theAccounts;
2018-06-01 14:48:29 +00:00
});
contract("SomeContract", function() {
this.timeout(0);
2018-04-17 18:48:31 +00:00
it("set MyToken2 address", async function() {
let address = await SomeContract.methods.addr_1().call();
2018-06-01 14:48:29 +00:00
assert.strictEqual(address, MyToken2.options.address);
});
2018-08-14 17:36:08 +00:00
it("set account address", async function() {
2018-04-17 18:48:31 +00:00
let address = await SomeContract.methods.addr_2().call();
2018-08-14 17:36:08 +00:00
assert.strictEqual(address, web3.eth.defaultAccount);
});
it("can sign using eth_signTypedData with a node 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: SomeContract.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
]);
// Impossible to tell what the signature will be because the account is not deterministic
assert.ok(signature);
});
});