2020-01-24 11:04:42 +00:00
|
|
|
/*global artifacts, contract, it, assert, before, web3*/
|
|
|
|
const SimpleStorage = artifacts.require('SimpleStorage');
|
|
|
|
const {Utils} = artifacts.require('EmbarkJS');
|
2018-06-07 23:08:18 +00:00
|
|
|
|
|
|
|
contract("SimpleStorage Deploy", function () {
|
2018-09-11 13:45:50 +00:00
|
|
|
let simpleStorageInstance;
|
2019-06-18 18:01:10 +00:00
|
|
|
before(async () => {
|
2020-02-19 15:32:29 +00:00
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
const gas = await SimpleStorage.deploy({arguments: [150]}).estimateGas();
|
|
|
|
|
|
|
|
Utils.secureSend(web3, SimpleStorage.deploy({arguments: [150]}), {gas, from: web3.eth.defaultAccount}, true, function(err, receipt) {
|
|
|
|
if(err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
simpleStorageInstance = SimpleStorage;
|
|
|
|
simpleStorageInstance.options.address = receipt.contractAddress;
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
2018-06-07 23:08:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should set constructor value", async function () {
|
2018-09-11 13:45:50 +00:00
|
|
|
let result = await simpleStorageInstance.methods.storedData().call();
|
2018-06-07 23:08:18 +00:00
|
|
|
assert.strictEqual(parseInt(result, 10), 150);
|
|
|
|
});
|
|
|
|
|
2019-10-22 13:27:22 +00:00
|
|
|
it("set storage value", function() {
|
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
const gas = await simpleStorageInstance.methods.set(200).estimateGas();
|
|
|
|
Utils.secureSend(web3, simpleStorageInstance.methods.set(200), {gas}, false, async function(err) {
|
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
let result = await simpleStorageInstance.methods.get().call();
|
|
|
|
assert.strictEqual(parseInt(result, 10), 200);
|
|
|
|
resolve();
|
|
|
|
});
|
2018-09-11 13:45:50 +00:00
|
|
|
});
|
2018-06-07 23:08:18 +00:00
|
|
|
});
|
|
|
|
});
|