1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00
This commit is contained in:
Ahmed Ali 2020-06-29 18:20:56 +02:00
parent 5ac2a05172
commit 5f95c67e3e
2 changed files with 38 additions and 21 deletions

View File

@ -193,7 +193,11 @@ export class DataTokens {
* @param dataTokenAddress * @param dataTokenAddress
* @param account * @param account
*/ */
public async allowance(dataTokenAddress: string, owner: string, spender: string): Promise<string> { public async allowance(
dataTokenAddress: string,
owner: string,
spender: string
): Promise<string> {
const datatoken = new this.web3.eth.Contract( const datatoken = new this.web3.eth.Contract(
this.datatokensABI, this.datatokensABI,
dataTokenAddress, dataTokenAddress,

View File

@ -98,19 +98,21 @@ describe('Marketplace flow', () => {
}) })
it('Alice allows marketplace to sell her datatokens', async () => { it('Alice allows marketplace to sell her datatokens', async () => {
await datatoken.approve( await datatoken
tokenAddress, .approve(
marketplace.getId(),
marketplaceAllowance,
alice.getId()
).then(async () => {
const allowance = await datatoken.allowance(
tokenAddress, tokenAddress,
alice.getId(), marketplace.getId(),
marketplace.getId() marketplaceAllowance,
alice.getId()
) )
assert(allowance.toString() === marketplaceAllowance.toString()) .then(async () => {
}) const allowance = await datatoken.allowance(
tokenAddress,
alice.getId(),
marketplace.getId()
)
assert(allowance.toString() === marketplaceAllowance.toString())
})
}) })
it('Marketplace withdraw Alice tokens from allowance', async () => { it('Marketplace withdraw Alice tokens from allowance', async () => {
@ -119,11 +121,17 @@ describe('Marketplace flow', () => {
alice.getId(), alice.getId(),
marketplace.getId() marketplace.getId()
) )
await datatoken.transferFrom(tokenAddress, alice.getId(), allowance, marketplace.getId()) await datatoken
.then(async () => { .transferFrom(tokenAddress, alice.getId(), allowance, marketplace.getId())
const marketplaceBalance = await datatoken.balance(tokenAddress, marketplace.getId()) .then(async () => {
assert(marketplaceBalance.toString() === marketplaceAllowance.toString()) const marketplaceBalance = await datatoken.balance(
}) tokenAddress,
marketplace.getId()
)
assert(
marketplaceBalance.toString() === marketplaceAllowance.toString()
)
})
}) })
// it('Marketplace posts asset for sale', async () => { // it('Marketplace posts asset for sale', async () => {
@ -136,7 +144,12 @@ describe('Marketplace flow', () => {
// }) // })
it('Bob gets datatokens', async () => { it('Bob gets datatokens', async () => {
const ts = await datatoken.transfer(tokenAddress, bob.getId(), transferAmount, alice.getId()) const ts = await datatoken.transfer(
tokenAddress,
bob.getId(),
transferAmount,
alice.getId()
)
transactionId = ts.transactionHash transactionId = ts.transactionHash
}) })