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 SomeContract = artifacts.require('SomeContract');
|
|
|
|
const MyToken2 = artifacts.require('MyToken2');
|
2018-06-01 14:48:29 +00:00
|
|
|
|
2020-02-19 15:47:59 +00:00
|
|
|
let accounts;
|
2018-06-01 14:48:29 +00:00
|
|
|
config({
|
|
|
|
contracts: {
|
2019-08-30 20:50:20 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2020-02-19 15:47:59 +00:00
|
|
|
}, (err, theAccounts) => {
|
|
|
|
accounts = theAccounts;
|
2018-06-01 14:48:29 +00:00
|
|
|
});
|
|
|
|
|
2018-03-04 23:46:12 +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-03-04 23:46:12 +00:00
|
|
|
});
|
|
|
|
|
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);
|
2018-03-04 23:46:12 +00:00
|
|
|
});
|
|
|
|
|
2020-02-19 15:47:59 +00:00
|
|
|
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);
|
|
|
|
});
|
2018-03-04 23:46:12 +00:00
|
|
|
});
|