mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fix start order and multi order
This commit is contained in:
parent
6c9746a8ad
commit
8c9e21f309
@ -847,13 +847,7 @@ export class Datatoken {
|
|||||||
address: string,
|
address: string,
|
||||||
consumer: string,
|
consumer: string,
|
||||||
serviceIndex: number,
|
serviceIndex: number,
|
||||||
providerFeeAddress: string,
|
providerFees: ProviderFees,
|
||||||
providerFeeToken: string,
|
|
||||||
providerFeeAmount: string,
|
|
||||||
v: string,
|
|
||||||
r: string,
|
|
||||||
s: string,
|
|
||||||
providerDatas: string,
|
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const dtContract =
|
const dtContract =
|
||||||
@ -864,17 +858,7 @@ export class Datatoken {
|
|||||||
let estGas
|
let estGas
|
||||||
try {
|
try {
|
||||||
estGas = await dtContract.methods
|
estGas = await dtContract.methods
|
||||||
.startOrder(
|
.startOrder(consumer, serviceIndex, providerFees)
|
||||||
consumer,
|
|
||||||
serviceIndex,
|
|
||||||
providerFeeAddress,
|
|
||||||
providerFeeToken,
|
|
||||||
providerFeeAmount,
|
|
||||||
v,
|
|
||||||
r,
|
|
||||||
s,
|
|
||||||
providerDatas
|
|
||||||
)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
estGas = gasLimitDefault
|
estGas = gasLimitDefault
|
||||||
@ -901,17 +885,9 @@ export class Datatoken {
|
|||||||
address: string,
|
address: string,
|
||||||
consumer: string,
|
consumer: string,
|
||||||
serviceIndex: number,
|
serviceIndex: number,
|
||||||
providerFeeAddress: string,
|
providerFees: ProviderFees
|
||||||
providerFeeToken: string,
|
|
||||||
providerFeeAmount: string,
|
|
||||||
v: string,
|
|
||||||
r: string,
|
|
||||||
s: string,
|
|
||||||
providerDatas: string
|
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
||||||
if (!providerFeeAddress)
|
|
||||||
providerFeeAddress = '0x0000000000000000000000000000000000000000'
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const estGas = await this.estGasStartOrder(
|
const estGas = await this.estGasStartOrder(
|
||||||
@ -919,28 +895,12 @@ export class Datatoken {
|
|||||||
address,
|
address,
|
||||||
consumer,
|
consumer,
|
||||||
serviceIndex,
|
serviceIndex,
|
||||||
providerFeeAddress,
|
providerFees,
|
||||||
providerFeeToken,
|
|
||||||
providerFeeAmount,
|
|
||||||
v,
|
|
||||||
r,
|
|
||||||
s,
|
|
||||||
providerDatas,
|
|
||||||
dtContract
|
dtContract
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
.startOrder(
|
.startOrder(consumer, serviceIndex, providerFees)
|
||||||
consumer,
|
|
||||||
serviceIndex,
|
|
||||||
providerFeeAddress,
|
|
||||||
providerFeeToken,
|
|
||||||
providerFeeAmount,
|
|
||||||
v,
|
|
||||||
r,
|
|
||||||
s,
|
|
||||||
providerDatas
|
|
||||||
)
|
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
|
@ -377,15 +377,16 @@ describe('Nft Factory test', () => {
|
|||||||
expect(await dtContract2.methods.balanceOf(user2).call()).to.equal(dtAmount)
|
expect(await dtContract2.methods.balanceOf(user2).call()).to.equal(dtAmount)
|
||||||
|
|
||||||
const providerData = JSON.stringify({ timeout: 0 })
|
const providerData = JSON.stringify({ timeout: 0 })
|
||||||
|
const providerValidUntil = '0'
|
||||||
const message = web3.utils.soliditySha3(
|
const message = web3.utils.soliditySha3(
|
||||||
{ t: 'bytes', v: web3.utils.toHex(web3.utils.asciiToHex(providerData)) },
|
{ t: 'bytes', v: web3.utils.toHex(web3.utils.asciiToHex(providerData)) },
|
||||||
{ t: 'address', v: consumeFeeAddress },
|
{ t: 'address', v: consumeFeeAddress },
|
||||||
{ t: 'address', v: consumeFeeToken },
|
{ t: 'address', v: consumeFeeToken },
|
||||||
{ t: 'uint256', v: web3.utils.toWei(consumeFeeAmount) }
|
{ t: 'uint256', v: web3.utils.toWei(consumeFeeAmount) },
|
||||||
|
{ t: 'uint256', v: providerValidUntil }
|
||||||
)
|
)
|
||||||
|
|
||||||
const { v, r, s } = await signHash(web3, message, consumeFeeAddress)
|
const { v, r, s } = await signHash(web3, message, consumeFeeAddress)
|
||||||
const providerValidUntil = '0'
|
|
||||||
const providerFees: ProviderFees = {
|
const providerFees: ProviderFees = {
|
||||||
providerFeeAddress: consumeFeeAddress,
|
providerFeeAddress: consumeFeeAddress,
|
||||||
providerFeeToken: consumeFeeToken,
|
providerFeeToken: consumeFeeToken,
|
||||||
@ -410,11 +411,11 @@ describe('Nft Factory test', () => {
|
|||||||
_providerFees: providerFees
|
_providerFees: providerFees
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
// console.log('orders', orders)
|
console.log('orders', orders)
|
||||||
// await nftFactory.startMultipleTokenOrder(user2, orders)
|
await nftFactory.startMultipleTokenOrder(user2, orders)
|
||||||
// // we check user2 has no more DTs
|
// we check user2 has no more DTs
|
||||||
// expect(await dtContract.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await dtContract.methods.balanceOf(user2).call()).to.equal('0')
|
||||||
// expect(await dtContract2.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await dtContract2.methods.balanceOf(user2).call()).to.equal('0')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#checkDatatoken - should confirm if DT is from the factory', async () => {
|
it('#checkDatatoken - should confirm if DT is from the factory', async () => {
|
||||||
|
@ -202,7 +202,7 @@ describe('SideStaking unit test', () => {
|
|||||||
contracts.sideStakingAddress,
|
contracts.sideStakingAddress,
|
||||||
erc20Token
|
erc20Token
|
||||||
)
|
)
|
||||||
).to.equal(web3.utils.toWei('12000'))
|
).to.equal(web3.utils.toWei('2000'))
|
||||||
})
|
})
|
||||||
it('#getDatatokenCurrentCirculatingSupply - should get datatoken supply in circulation ', async () => {
|
it('#getDatatokenCurrentCirculatingSupply - should get datatoken supply in circulation ', async () => {
|
||||||
expect(
|
expect(
|
||||||
@ -235,7 +235,7 @@ describe('SideStaking unit test', () => {
|
|||||||
it('#getDatatokenBalance ', async () => {
|
it('#getDatatokenBalance ', async () => {
|
||||||
expect(
|
expect(
|
||||||
await sideStaking.getDatatokenBalance(sideStakingAddress, erc20Token)
|
await sideStaking.getDatatokenBalance(sideStakingAddress, erc20Token)
|
||||||
).to.equal('988000')
|
).to.equal('997999.9999999999')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getvestingAmount ', async () => {
|
it('#getvestingAmount ', async () => {
|
||||||
@ -495,7 +495,7 @@ describe('SideStaking unit test', () => {
|
|||||||
it('#getDatatokenBalance ', async () => {
|
it('#getDatatokenBalance ', async () => {
|
||||||
expect(
|
expect(
|
||||||
await sideStaking.getDatatokenBalance(sideStakingAddress, erc20Token)
|
await sideStaking.getDatatokenBalance(sideStakingAddress, erc20Token)
|
||||||
).to.equal('988000')
|
).to.equal('997999.9999999999')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getvestingAmount ', async () => {
|
it('#getvestingAmount ', async () => {
|
||||||
|
@ -345,25 +345,31 @@ describe('Datatoken', () => {
|
|||||||
const providerData = JSON.stringify({ timeout: 0 })
|
const providerData = JSON.stringify({ timeout: 0 })
|
||||||
const providerFeeToken = ZERO_ADDRESS
|
const providerFeeToken = ZERO_ADDRESS
|
||||||
const providerFeeAmount = '0'
|
const providerFeeAmount = '0'
|
||||||
|
const providerValidUntil = '0'
|
||||||
const message = web3.utils.soliditySha3(
|
const message = web3.utils.soliditySha3(
|
||||||
{ t: 'bytes', v: web3.utils.toHex(web3.utils.asciiToHex(providerData)) },
|
{ t: 'bytes', v: web3.utils.toHex(web3.utils.asciiToHex(providerData)) },
|
||||||
{ t: 'address', v: user3 },
|
{ t: 'address', v: user3 },
|
||||||
{ t: 'address', v: providerFeeToken },
|
{ t: 'address', v: providerFeeToken },
|
||||||
{ t: 'uint256', v: providerFeeAmount }
|
{ t: 'uint256', v: providerFeeAmount },
|
||||||
|
{ t: 'uint256', v: providerValidUntil }
|
||||||
)
|
)
|
||||||
const { v, r, s } = await signHash(web3, message, user3)
|
const { v, r, s } = await signHash(web3, message, user3)
|
||||||
|
const providerFees: ProviderFees = {
|
||||||
|
providerFeeAddress: user3,
|
||||||
|
providerFeeToken: providerFeeToken,
|
||||||
|
providerFeeAmount: providerFeeAmount,
|
||||||
|
v: v,
|
||||||
|
r: r,
|
||||||
|
s: s,
|
||||||
|
providerData: web3.utils.toHex(web3.utils.asciiToHex(providerData)),
|
||||||
|
validUntil: providerValidUntil
|
||||||
|
}
|
||||||
const order = await datatoken.startOrder(
|
const order = await datatoken.startOrder(
|
||||||
datatokenAddress,
|
datatokenAddress,
|
||||||
user1,
|
user1,
|
||||||
user2,
|
user2,
|
||||||
1,
|
1,
|
||||||
user3,
|
providerFees
|
||||||
providerFeeToken,
|
|
||||||
providerFeeAmount,
|
|
||||||
v,
|
|
||||||
r,
|
|
||||||
s,
|
|
||||||
web3.utils.toHex(web3.utils.asciiToHex(providerData))
|
|
||||||
)
|
)
|
||||||
assert(order !== null)
|
assert(order !== null)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user