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(
|
const datatoken = new this.web3.eth.Contract(
|
||||||
this.datatokensABI,
|
this.datatokensABI,
|
||||||
dataTokenAddress,
|
dataTokenAddress,
|
||||||
{ from: account.getId() }
|
{ from: account }
|
||||||
)
|
)
|
||||||
const trxReceipt = await datatoken.methods.approve(spender, amount).send()
|
const trxReceipt = await datatoken.methods.approve(spender, amount).send()
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
@ -147,7 +147,7 @@ export class DataTokens {
|
|||||||
const datatoken = new this.web3.eth.Contract(
|
const datatoken = new this.web3.eth.Contract(
|
||||||
this.datatokensABI,
|
this.datatokensABI,
|
||||||
dataTokenAddress,
|
dataTokenAddress,
|
||||||
{ from: account.getId() }
|
{ from: account }
|
||||||
)
|
)
|
||||||
const trxReceipt = await datatoken.methods.transfer(toAddress, amount).send()
|
const trxReceipt = await datatoken.methods.transfer(toAddress, amount).send()
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
@ -170,10 +170,10 @@ export class DataTokens {
|
|||||||
const datatoken = new this.web3.eth.Contract(
|
const datatoken = new this.web3.eth.Contract(
|
||||||
this.datatokensABI,
|
this.datatokensABI,
|
||||||
dataTokenAddress,
|
dataTokenAddress,
|
||||||
{ from: account.getId() }
|
{ from: account }
|
||||||
)
|
)
|
||||||
const trxReceipt = await datatoken.methods
|
const trxReceipt = await datatoken.methods
|
||||||
.transferFrom(fromAddress, account.getId(), amount)
|
.transferFrom(fromAddress, account, amount)
|
||||||
.send()
|
.send()
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ const datatokensABI = require('../../src/datatokens/DatatokensABI.json')
|
|||||||
describe('DataTokens', () => {
|
describe('DataTokens', () => {
|
||||||
|
|
||||||
let minter
|
let minter
|
||||||
|
let spender
|
||||||
|
let balance
|
||||||
let contracts
|
let contracts
|
||||||
let datatoken
|
let datatoken
|
||||||
let tokenAddress
|
let tokenAddress
|
||||||
@ -18,15 +20,15 @@ describe('DataTokens', () => {
|
|||||||
let tokenAmount = 100
|
let tokenAmount = 100
|
||||||
let blob = 'https://example.com/dataset-1'
|
let blob = 'https://example.com/dataset-1'
|
||||||
|
|
||||||
beforeEach(async () => {
|
describe('#test', () => {
|
||||||
|
it('should deploy contracts', async () => {
|
||||||
contracts = new TestContractHandler(factoryABI,datatokensABI)
|
contracts = new TestContractHandler(factoryABI,datatokensABI)
|
||||||
await contracts.getAccounts()
|
await contracts.getAccounts()
|
||||||
|
|
||||||
minter = contracts.accounts[0]
|
minter = contracts.accounts[0]
|
||||||
|
spender = contracts.accounts[1]
|
||||||
await contracts.deployContracts(minter)
|
await contracts.deployContracts(minter)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#test', () => {
|
|
||||||
it('should create Datatoken object', async () => {
|
it('should create Datatoken object', async () => {
|
||||||
datatoken = new DataTokens(contracts.factoryAddress, factoryABI, datatokensABI, web3)
|
datatoken = new DataTokens(contracts.factoryAddress, factoryABI, datatokensABI, web3)
|
||||||
assert(datatoken !== null)
|
assert(datatoken !== null)
|
||||||
@ -38,10 +40,27 @@ describe('DataTokens', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should mint Datatokens', async () => {
|
it('should mint Datatokens', async () => {
|
||||||
const tokenAddress = await datatoken.create(blob, minter)
|
|
||||||
await datatoken.mint(tokenAddress, minter, tokenAmount)
|
await datatoken.mint(tokenAddress, minter, tokenAmount)
|
||||||
let balance = await datatoken.balance(tokenAddress, minter)
|
balance = await datatoken.balance(tokenAddress, minter)
|
||||||
assert(balance.toString() === tokenAmount.toString())
|
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