1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| const ganache = require('ganache-cli');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider()); const {bytecode,interface} = require('../compile'); const assert = require('assert');
var helloworld; var fetchAccounts; beforeEach( async()=>{ fetchAccounts = await web3.eth.getAccounts(); helloworld = await new web3.eth.Contract(JSON.parse(interface)).deploy({data:bytecode,arguments:['jonson']}).send({from:fetchAccounts[0],gas:'1000000'}); console.log(fetchAccounts); });
describe('HelloWorld',()=>{
it('deploy contract',()=>{ assert.ok(helloworld.options.address); })
it('call static function',async ()=>{ const message = await helloworld.methods.getName().call(); assert.equal('jonson',message); })
it('call dynamic function',async ()=>{ await helloworld.methods.changeName('olaya').send({from:fetchAccounts[0]}); const message = await helloworld.methods.getName().call(); assert.equal('olaya',message); })
})
|