diff --git a/src/datatokens/Datatokens.ts b/src/datatokens/Datatokens.ts index 79de6144..a90f1435 100644 --- a/src/datatokens/Datatokens.ts +++ b/src/datatokens/Datatokens.ts @@ -159,7 +159,7 @@ export class DataTokens { dataTokenAddress: string, fromAddress: string, amount: number, - account: Account + account: string ): Promise { const datatoken = new this.web3.eth.Contract( this.datatokensABI, @@ -188,6 +188,21 @@ export class DataTokens { return trxReceipt } + /** + * + * @param dataTokenAddress + * @param account + */ + public async allowance(dataTokenAddress: string, owner: string, spender: string): Promise { + const datatoken = new this.web3.eth.Contract( + this.datatokensABI, + dataTokenAddress, + { from: spender } + ) + const trxReceipt = await datatoken.methods.allowance(owner, spender).call() + return trxReceipt + } + /** Get Blob * @param {String} dataTokenAddress * @param {Account} account diff --git a/test/integration/Marketplaceflow.test.ts b/test/integration/Marketplaceflow.test.ts index 6a74b676..0875492f 100644 --- a/test/integration/Marketplaceflow.test.ts +++ b/test/integration/Marketplaceflow.test.ts @@ -29,6 +29,7 @@ describe('Marketplace flow', () => { let ocean + const marketplaceAllowance = 20 const tokenAmount = 100 const transferAmount = 2 const blob = 'http://localhost:8030/api/v1/provider/services' @@ -89,13 +90,42 @@ describe('Marketplace flow', () => { it('Alice publishes a dataset', async () => { ddo = await ocean.assets.create(asset, alice, [], tokenAddress) - assert(ddo != null) + assert(ddo.dataToken === tokenAddress) }) it('Alice mints 100 tokens', async () => { await datatoken.mint(tokenAddress, alice.getId(), tokenAmount) }) + it('Alice allows marketplace to sell her datatokens', async () => { + await datatoken.approve( + tokenAddress, + marketplace.getId(), + marketplaceAllowance, + alice.getId() + ).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 () => { + const allowance = await datatoken.allowance( + tokenAddress, + alice.getId(), + marketplace.getId() + ) + await datatoken.transferFrom(tokenAddress, alice.getId(), allowance, marketplace.getId()) + .then(async () => { + const marketplaceBalance = await datatoken.balance(tokenAddress, marketplace.getId()) + assert(marketplaceBalance.toString() === marketplaceAllowance.toString()) + }) + }) + // it('Marketplace posts asset for sale', async () => { // const config = new Config() // marketOcean = await Ocean.getInstance(config)