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
|
|
|
|