2019-06-20 00:20:09 +02:00
|
|
|
import { assert } from 'chai'
|
2020-01-30 22:08:18 +01:00
|
|
|
import Account from '../../../src/ocean/Account'
|
|
|
|
import { Ocean } from '../../../src/ocean/Ocean'
|
2019-06-20 00:20:09 +02:00
|
|
|
import config from '../config'
|
2020-01-29 14:38:44 +01:00
|
|
|
import ContractBaseMock from '../__mocks__/ContractBase.Mock'
|
2019-06-20 00:20:09 +02:00
|
|
|
import TestContractHandler from './TestContractHandler'
|
|
|
|
|
|
|
|
const wrappedContract = new ContractBaseMock('OceanToken')
|
2018-10-29 17:28:40 +01:00
|
|
|
let accounts: Account[]
|
2018-10-18 09:19:10 +02:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('ContractWrapperBase', () => {
|
2018-10-26 10:40:46 +02:00
|
|
|
before(async () => {
|
2018-11-07 14:33:56 +01:00
|
|
|
await TestContractHandler.prepareContracts()
|
2018-10-29 17:28:40 +01:00
|
|
|
const ocean: Ocean = await Ocean.getInstance(config)
|
2019-03-21 02:56:58 +01:00
|
|
|
accounts = await ocean.accounts.list()
|
2019-03-21 03:17:36 +01:00
|
|
|
await wrappedContract.initMock((ocean as any).instanceConfig)
|
2018-10-26 10:40:46 +02:00
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#call()', () => {
|
2020-05-19 16:15:56 +02:00
|
|
|
it('should fail to call on an unknown contract function', (done) => {
|
2019-06-20 00:20:09 +02:00
|
|
|
wrappedContract.callMock('balanceOfxxx', []).catch(() => {
|
|
|
|
done()
|
|
|
|
})
|
2018-10-18 09:19:10 +02:00
|
|
|
})
|
|
|
|
|
2020-05-19 16:15:56 +02:00
|
|
|
it('should fail to call on an contract function with wrong set of parameters', (done) => {
|
2019-06-20 00:20:09 +02:00
|
|
|
wrappedContract.callMock('balanceOf', []).catch(() => {
|
|
|
|
done()
|
|
|
|
})
|
2018-10-18 09:19:10 +02:00
|
|
|
})
|
|
|
|
|
2020-05-19 16:15:56 +02:00
|
|
|
it('should fail to call on an unknown contract function', (done) => {
|
2019-09-09 12:18:54 +02:00
|
|
|
wrappedContract.sendMock('balanceOfxxx', '0x00', ['0x00']).catch(() => {
|
|
|
|
done()
|
|
|
|
})
|
2018-10-18 09:19:10 +02:00
|
|
|
})
|
|
|
|
|
2020-05-19 16:15:56 +02:00
|
|
|
it('should fail to call on an contract function with wrong set of parameters', (done) => {
|
2019-06-20 00:20:09 +02:00
|
|
|
wrappedContract.sendMock('approve', '0x000', []).catch(() => {
|
|
|
|
done()
|
|
|
|
})
|
2018-10-18 09:19:10 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#send()', () => {
|
2020-05-19 16:15:56 +02:00
|
|
|
it('should fail to call on an unknown contract function', (done) => {
|
2019-09-09 12:18:54 +02:00
|
|
|
wrappedContract.sendMock('transferxxx', accounts[0].getId(), []).catch(() => {
|
|
|
|
done()
|
|
|
|
})
|
2018-10-29 17:28:40 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#getSignatureOfMethod()', () => {
|
|
|
|
it('should a signature of the function', async () => {
|
|
|
|
const sig = wrappedContract.getSignatureOfMethod('name')
|
2018-10-29 17:28:40 +01:00
|
|
|
assert(sig)
|
2019-06-20 00:20:09 +02:00
|
|
|
assert(typeof sig === 'string')
|
|
|
|
assert(sig.startsWith('0x'))
|
2018-10-29 17:28:40 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#getEventData()', () => {
|
2020-05-19 16:15:56 +02:00
|
|
|
it('should fail on unknown event', (done) => {
|
2019-06-20 00:20:09 +02:00
|
|
|
wrappedContract.getEventData('crazyevent', {}).catch(() => {
|
|
|
|
done()
|
|
|
|
})
|
2018-10-18 09:19:10 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|