Completed
Pull Request — master (#8)
by Nguyen
02:03
created

test/Inbox.test.js   A

Complexity

Total Complexity 7
Complexity/F 1.17

Size

Lines of Code 29
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 7
eloc 18
nc 1
mnd 0
bc 6
fnc 6
dl 0
loc 29
bpm 1
cpm 1.1666
noi 2
c 1
b 0
f 0
rs 10
1
const assert = require('assert');
2
const ganache = require('ganache-cli');
3
const Web3 = require('web3');
4
const provider = ganache.provider();
5
const web3 = new Web3(provider);
6
7
const {interface, bytecode} = require('../compile');
8
const INITIAL_MESSAGE = 'Hello Solidity';
9
let accounts;
10
let inbox;
11
beforeEach(async() => {
12
  // get a list of all accounts
13
  accounts = await web3.eth.getAccounts();
14
15
  // use one of those accounts to deploy the contracts
16
  inbox = await new web3.eth.Contract(JSON.parse(interface))
17
  .deploy({data: bytecode, arguments: [INITIAL_MESSAGE]})
18
  .send({from: accounts[0], gas: '1000000'})
19
20
  inbox.setProvider(provider);
21
});
22
23
describe('Get Accounts', () => {
24
  it('is deployment success', () => {
25
    // console.log(accounts);
26
    // console.log(inbox);
27
28
    // make sure inbox.options.address is not undefined
29
    assert.ok(inbox.options.address);
30
  });
31
32
  it('test default message', async() => {
33
    const MESSAGE = await inbox.methods.message().call();
34
    assert.equal(MESSAGE, INITIAL_MESSAGE);
35
  });
36
37
38
    it('test setMessage', async() => {
39
      const NEW_MESSAGE = 'Nguyen is in blockchain technology';
40
      await inbox.methods.setMessage(NEW_MESSAGE)
41
      .send({from: accounts[0], gas: '1000000'});
42
      const MESSAGE = await inbox.methods.message().call();
43
      assert.equal(MESSAGE, NEW_MESSAGE);
44
    });
45
});
46