mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fix allowance in datatoken
This commit is contained in:
parent
2025527f97
commit
6adac7b6f5
@ -159,7 +159,7 @@ export class DataTokens {
|
|||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
fromAddress: string,
|
fromAddress: string,
|
||||||
amount: number,
|
amount: number,
|
||||||
account: Account
|
account: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const datatoken = new this.web3.eth.Contract(
|
const datatoken = new this.web3.eth.Contract(
|
||||||
this.datatokensABI,
|
this.datatokensABI,
|
||||||
@ -188,6 +188,21 @@ export class DataTokens {
|
|||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param dataTokenAddress
|
||||||
|
* @param account
|
||||||
|
*/
|
||||||
|
public async allowance(dataTokenAddress: string, owner: string, spender: string): Promise<string> {
|
||||||
|
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
|
/** Get Blob
|
||||||
* @param {String} dataTokenAddress
|
* @param {String} dataTokenAddress
|
||||||
* @param {Account} account
|
* @param {Account} account
|
||||||
|
@ -29,6 +29,7 @@ describe('Marketplace flow', () => {
|
|||||||
|
|
||||||
let ocean
|
let ocean
|
||||||
|
|
||||||
|
const marketplaceAllowance = 20
|
||||||
const tokenAmount = 100
|
const tokenAmount = 100
|
||||||
const transferAmount = 2
|
const transferAmount = 2
|
||||||
const blob = 'http://localhost:8030/api/v1/provider/services'
|
const blob = 'http://localhost:8030/api/v1/provider/services'
|
||||||
@ -89,13 +90,42 @@ describe('Marketplace flow', () => {
|
|||||||
|
|
||||||
it('Alice publishes a dataset', async () => {
|
it('Alice publishes a dataset', async () => {
|
||||||
ddo = await ocean.assets.create(asset, alice, [], tokenAddress)
|
ddo = await ocean.assets.create(asset, alice, [], tokenAddress)
|
||||||
assert(ddo != null)
|
assert(ddo.dataToken === tokenAddress)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Alice mints 100 tokens', async () => {
|
it('Alice mints 100 tokens', async () => {
|
||||||
await datatoken.mint(tokenAddress, alice.getId(), tokenAmount)
|
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 () => {
|
// it('Marketplace posts asset for sale', async () => {
|
||||||
// const config = new Config()
|
// const config = new Config()
|
||||||
// marketOcean = await Ocean.getInstance(config)
|
// marketOcean = await Ocean.getInstance(config)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user