/ test / simple_storage_spec.js
simple_storage_spec.js
 1  /*global contract, config, it, assert*/
 2  const SimpleStorage = require('Embark/contracts/SimpleStorage');
 3  const EmbarkJS = require('Embark/EmbarkJS');
 4  
 5  let accounts;
 6  
 7  // For documentation please see https://embark.status.im/docs/contracts_testing.html
 8  config({
 9    // deployment: {
10    //   host: "localhost",
11    //   port: 8545,
12    //   type: "rpc"
13    // },
14    contracts: {
15      "SimpleStorage": {
16        args: [100]
17      }
18    }
19  }, (_err, web3_accounts) => {
20    accounts = web3_accounts
21  });
22  
23  contract("SimpleStorage", function () {
24    this.timeout(0);
25    before(done => {
26      setTimeout(done, 2000);
27    });
28  
29    it('should have access to ENS functions', function(done) {
30      EmbarkJS.Names.resolve('eth', (err, addr) => {
31        if (err) {
32          return done(err);
33        }
34        try{
35          assert.strictEqual(addr, web3.eth.defaultAccount);
36          done();
37        } catch (e) {
38          done(e);
39        }
40      });
41    });
42  
43    it('should have access to Storage functions', async function() {
44      const hash = await EmbarkJS.Storage.saveText('myText');
45      const text = await EmbarkJS.Storage.get(hash);
46      assert.strictEqual(text, 'myText');
47    });
48  
49    it("should set constructor value", async function () {
50      let result = await SimpleStorage.methods.storedData().call();
51      assert.strictEqual(parseInt(result, 10), 100);
52    });
53  
54    it("set storage value", async function () {
55      await SimpleStorage.methods.set(150).send();
56      let result = await SimpleStorage.methods.get().call();
57      assert.strictEqual(parseInt(result, 10), 150);
58    });
59  
60    it("should have account with balance", async function() {
61      let balance = await web3.eth.getBalance(accounts[0]);
62      assert.ok(parseInt(balance, 10) > 0);
63    });
64  });