mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
add more tests
This commit is contained in:
parent
ad3d42f7b1
commit
73b7a42e79
@ -88,7 +88,7 @@ export class DataTokens {
|
||||
const datatoken = new this.web3.eth.Contract(
|
||||
this.datatokensABI,
|
||||
dataTokenAddress,
|
||||
{ from: account.getId() }
|
||||
{ from: account }
|
||||
)
|
||||
const trxReceipt = await datatoken.methods.approve(spender, amount).send()
|
||||
return trxReceipt
|
||||
@ -147,7 +147,7 @@ export class DataTokens {
|
||||
const datatoken = new this.web3.eth.Contract(
|
||||
this.datatokensABI,
|
||||
dataTokenAddress,
|
||||
{ from: account.getId() }
|
||||
{ from: account }
|
||||
)
|
||||
const trxReceipt = await datatoken.methods.transfer(toAddress, amount).send()
|
||||
return trxReceipt
|
||||
@ -170,10 +170,10 @@ export class DataTokens {
|
||||
const datatoken = new this.web3.eth.Contract(
|
||||
this.datatokensABI,
|
||||
dataTokenAddress,
|
||||
{ from: account.getId() }
|
||||
{ from: account }
|
||||
)
|
||||
const trxReceipt = await datatoken.methods
|
||||
.transferFrom(fromAddress, account.getId(), amount)
|
||||
.transferFrom(fromAddress, account, amount)
|
||||
.send()
|
||||
return trxReceipt
|
||||
}
|
||||
@ -253,4 +253,4 @@ export class DataTokens {
|
||||
const trxReceipt = await datatoken.methods.cap().call()
|
||||
return trxReceipt
|
||||
}
|
||||
}
|
||||
}
|
@ -11,6 +11,8 @@ const datatokensABI = require('../../src/datatokens/DatatokensABI.json')
|
||||
describe('DataTokens', () => {
|
||||
|
||||
let minter
|
||||
let spender
|
||||
let balance
|
||||
let contracts
|
||||
let datatoken
|
||||
let tokenAddress
|
||||
@ -18,15 +20,15 @@ describe('DataTokens', () => {
|
||||
let tokenAmount = 100
|
||||
let blob = 'https://example.com/dataset-1'
|
||||
|
||||
beforeEach(async () => {
|
||||
contracts = new TestContractHandler(factoryABI,datatokensABI)
|
||||
await contracts.getAccounts()
|
||||
|
||||
minter = contracts.accounts[0]
|
||||
await contracts.deployContracts(minter)
|
||||
})
|
||||
|
||||
describe('#test', () => {
|
||||
it('should deploy contracts', async () => {
|
||||
contracts = new TestContractHandler(factoryABI,datatokensABI)
|
||||
await contracts.getAccounts()
|
||||
minter = contracts.accounts[0]
|
||||
spender = contracts.accounts[1]
|
||||
await contracts.deployContracts(minter)
|
||||
})
|
||||
|
||||
it('should create Datatoken object', async () => {
|
||||
datatoken = new DataTokens(contracts.factoryAddress, factoryABI, datatokensABI, web3)
|
||||
assert(datatoken !== null)
|
||||
@ -38,10 +40,27 @@ describe('DataTokens', () => {
|
||||
})
|
||||
|
||||
it('should mint Datatokens', async () => {
|
||||
const tokenAddress = await datatoken.create(blob, minter)
|
||||
await datatoken.mint(tokenAddress, minter, tokenAmount)
|
||||
let balance = await datatoken.balance(tokenAddress, minter)
|
||||
balance = await datatoken.balance(tokenAddress, minter)
|
||||
assert(balance.toString() === tokenAmount.toString())
|
||||
})
|
||||
|
||||
it('should transfer Datatokens to spender', async () => {
|
||||
await datatoken.transfer(tokenAddress, spender, tokenAmount, minter)
|
||||
balance = await datatoken.balance(tokenAddress, spender)
|
||||
assert(balance.toString() === tokenAmount.toString())
|
||||
|
||||
})
|
||||
|
||||
it('should approve Datatokens to spend', async () => {
|
||||
await datatoken.approve(tokenAddress, minter, tokenAmount, spender)
|
||||
})
|
||||
|
||||
it('should transferFrom Datatokens back to the minter', async () => {
|
||||
await datatoken.transferFrom(tokenAddress, spender, tokenAmount, minter)
|
||||
minter = await datatoken.balance(tokenAddress, spender)
|
||||
assert(balance.toString() === tokenAmount.toString())
|
||||
})
|
||||
|
||||
})
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user