2018-06-07 20:14:42 +00:00
|
|
|
/*global contract, config, it, assert, web3*/
|
|
|
|
const SimpleStorage = require('Embark/contracts/SimpleStorage');
|
2018-06-06 17:54:20 +00:00
|
|
|
let accounts;
|
2018-08-24 17:11:06 +00:00
|
|
|
const Utils = require('embarkjs').Utils;
|
2018-01-15 14:51:45 +00:00
|
|
|
|
2018-06-01 14:48:29 +00:00
|
|
|
config({
|
|
|
|
contracts: {
|
|
|
|
"SimpleStorage": {
|
2018-06-06 14:39:02 +00:00
|
|
|
args: [100],
|
2018-10-25 23:11:49 +00:00
|
|
|
onDeploy: ["SimpleStorage.methods.setRegistar('$SimpleStorage').send()"]
|
2018-06-01 14:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-06 17:54:20 +00:00
|
|
|
}, (err, theAccounts) => {
|
|
|
|
accounts = theAccounts;
|
2018-06-01 14:48:29 +00:00
|
|
|
});
|
2018-01-15 14:51:45 +00:00
|
|
|
|
2018-10-25 23:11:49 +00:00
|
|
|
contract("SimpleStorage", function() {
|
2018-01-05 20:10:47 +00:00
|
|
|
this.timeout(0);
|
2018-01-15 14:51:45 +00:00
|
|
|
|
2018-10-25 23:11:49 +00:00
|
|
|
it("should set constructor value", async function() {
|
2018-04-17 18:48:31 +00:00
|
|
|
let result = await SimpleStorage.methods.storedData().call();
|
2018-06-01 14:48:29 +00:00
|
|
|
assert.strictEqual(parseInt(result, 10), 100);
|
2017-02-10 00:38:02 +00:00
|
|
|
});
|
|
|
|
|
2018-10-25 23:11:49 +00:00
|
|
|
it("set storage value", function(done) {
|
2018-08-24 17:11:06 +00:00
|
|
|
Utils.secureSend(web3, SimpleStorage.methods.set(150), {}, false, async function(err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
let result = await SimpleStorage.methods.get().call();
|
|
|
|
assert.strictEqual(parseInt(result, 10), 150);
|
|
|
|
done();
|
|
|
|
});
|
2017-02-10 00:38:02 +00:00
|
|
|
});
|
2018-06-06 14:39:02 +00:00
|
|
|
|
2018-10-25 23:11:49 +00:00
|
|
|
it("should set to self address", async function() {
|
2018-06-06 14:39:02 +00:00
|
|
|
let result = await SimpleStorage.methods.registar().call();
|
2018-10-25 23:11:49 +00:00
|
|
|
assert.strictEqual(result, SimpleStorage.options.address);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have the right defaultAccount', function() {
|
2018-06-06 17:54:20 +00:00
|
|
|
assert.strictEqual(accounts[0], web3.eth.defaultAccount);
|
2018-06-06 14:39:02 +00:00
|
|
|
});
|
|
|
|
|
2018-10-25 23:11:49 +00:00
|
|
|
it("should alias contract address", function() {
|
2018-06-06 16:47:16 +00:00
|
|
|
assert.strictEqual(SimpleStorage.options.address, SimpleStorage.address);
|
|
|
|
});
|
|
|
|
|
2018-10-25 23:11:49 +00:00
|
|
|
it('listens to events', function(done) {
|
|
|
|
SimpleStorage.once('EventOnSet2', async function(error, _result) {
|
2018-07-03 20:39:17 +00:00
|
|
|
assert.strictEqual(error, null);
|
2018-06-12 15:38:25 +00:00
|
|
|
let result = await SimpleStorage.methods.get().call();
|
2018-07-03 20:39:17 +00:00
|
|
|
assert.strictEqual(parseInt(result, 10), 150);
|
2018-06-29 21:09:19 +00:00
|
|
|
done(error);
|
2018-06-12 15:38:25 +00:00
|
|
|
});
|
|
|
|
|
2018-09-14 19:21:45 +00:00
|
|
|
SimpleStorage.methods.set2(150).send();
|
2018-06-12 15:38:25 +00:00
|
|
|
});
|
|
|
|
|
2017-02-10 00:38:02 +00:00
|
|
|
});
|