Created
April 8, 2020 16:08
-
-
Save nakajo2011/5a35726bc8345ce9e747ecd8cad6cbb3 to your computer and use it in GitHub Desktop.
web3.js mocking sample unit test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Faucet = require('../src/model/faucet') | |
const CONTRACT_ADDRESS = '0xadDf5bC8b45571D94e2FD46Bfb81f8dD6D6f9FA0' | |
const FROM_ADDRESS = '0x259de638f0d6d79dfa084a810c1356d4d575b62e' | |
describe('Faucet', function () { | |
describe('init', function () { | |
it('should be return instance', async () => { | |
const ins = new Faucet(CONTRACT_ADDRESS, FROM_ADDRESS) | |
expect(ins).toBeDefined() | |
}) | |
}) | |
describe('test functions', function () { | |
it('getPastEventOption when block 100', async () => { | |
const ins = new Faucet(CONTRACT_ADDRESS, FROM_ADDRESS) | |
const option = await ins.getPastEventOption() | |
expect(option).toEqual({fromBlock: 0, toBlock: 'latest'}) | |
}) | |
it('getPastEventOption when block 65536', async () => { | |
// expect blockNumber to 65535 | |
const ins = new Faucet(CONTRACT_ADDRESS, FROM_ADDRESS) | |
const option = await ins.getPastEventOption() | |
expect(option).toEqual({fromBlock: (65535 - (24 * 60 * 4)), toBlock: 'latest'}) | |
}) | |
it('isAlreadyWitdrawed', async () => { | |
// expect getPastEvents return values include the address as to. | |
const ins = new Faucet(CONTRACT_ADDRESS, FROM_ADDRESS) | |
await ins.loadLatestDayTransfers() | |
const result = await ins.isAlreadyWitdrawed('0x259de638f0d6d79dfa084a810c1356d4d575b62e') | |
expect(result).toBeTruthy() | |
}) | |
it('sendToken', async () => { | |
// wanna check 2nd args specify 100. | |
const ins = new Faucet(CONTRACT_ADDRESS, FROM_ADDRESS) | |
const toAddress = '0xe62d87b603dc9b8a5535d41aa464f583cc476aa8' | |
await ins.sendToken(toAddress) | |
// check that send just 100 token. | |
expect(mockTransfer).toHaveBeenCalledWith(toAddress, 100) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment