embark/test_apps/contracts_app/test/token_spec.js

83 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-06-01 17:44:30 +00:00
/*global describe, config, it, embark*/
const assert = require('assert');
const Token = embark.require('Embark/contracts/Token');
const MyToken = embark.require('Embark/contracts/MyToken');
const MyToken2 = embark.require('Embark/contracts/MyToken2');
const AlreadyDeployedToken = embark.require('Embark/contracts/AlreadyDeployedToken');
const Test = embark.require('Embark/contracts/Test');
2018-01-15 14:51:45 +00:00
2018-06-01 17:44:30 +00:00
config({
contracts: {
ZAMyLib: {},
SimpleStorage: {
args: [100]
},
AnotherStorage: {
args: ["$SimpleStorage"]
},
Token: {
deploy: false,
args: [1000]
},
MyToken: {
instanceOf: "Token"
},
MyToken2: {
instanceOf: "Token",
args: [2000]
},
AlreadyDeployedToken: {
address: "0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE",
instanceOf: "Token"
},
Test: {
onDeploy: ["Test.methods.changeAddress('$MyToken').send()"]
},
ContractArgs: {
args: {
initialValue: 123,
_addresses: ["$MyToken2", "$SimpleStorage"]
}
},
SomeContract: {
args: [
["$MyToken2", "$SimpleStorage"],
100
]
}
}
});
2018-01-15 14:51:45 +00:00
2018-06-01 17:44:30 +00:00
describe("Token", function () {
2018-01-05 20:10:47 +00:00
this.timeout(0);
2018-01-15 14:51:45 +00:00
2018-06-01 17:44:30 +00:00
it("not deploy Token", function () {
assert.strictEqual(Token.address, undefined);
2017-02-10 02:05:45 +00:00
});
2018-06-01 17:44:30 +00:00
it("should deploy MyToken and MyToken2", function () {
assert.ok(MyToken.options.address);
assert.ok(MyToken2.options.address);
2017-02-10 02:05:45 +00:00
});
2018-06-01 17:44:30 +00:00
it("set MyToken Balance correctly", async function () {
2018-04-17 18:48:31 +00:00
let result = await MyToken.methods._supply().call();
2018-06-01 17:44:30 +00:00
assert.strictEqual(parseInt(result, 10), 1000);
2017-02-10 02:05:45 +00:00
});
2018-06-01 17:44:30 +00:00
it("set MyToken2 Balance correctly", async function () {
2018-04-17 18:48:31 +00:00
let result = await MyToken2.methods._supply().call();
2018-06-01 17:44:30 +00:00
assert.strictEqual(parseInt(result, 10), 2000);
2017-02-10 02:05:45 +00:00
});
2018-06-01 17:44:30 +00:00
it("get right address", function () {
assert.strictEqual(AlreadyDeployedToken.options.address.toLowerCase(),
"0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE".toLowerCase());
2017-02-10 02:05:45 +00:00
});
2018-06-01 17:44:30 +00:00
it("should use onDeploy", async function () {
2018-04-17 18:48:31 +00:00
let result = await Test.methods.addr().call();
2018-06-01 17:44:30 +00:00
assert.strictEqual(result, MyToken.options.address);
2017-12-20 19:09:35 +00:00
});
2017-02-10 02:05:45 +00:00
});