mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
fixing second test: testing provider fees after calling reuseOrder on a using a previous txId
This commit is contained in:
parent
70db07e17e
commit
f848d419b0
@ -82,6 +82,7 @@ describe('Simple Publish & consume test', async () => {
|
|||||||
let user1: string
|
let user1: string
|
||||||
let user2: string
|
let user2: string
|
||||||
let user3: string
|
let user3: string
|
||||||
|
let user4: string
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
nft = new Nft(web3)
|
nft = new Nft(web3)
|
||||||
@ -92,6 +93,7 @@ describe('Simple Publish & consume test', async () => {
|
|||||||
user1 = accounts[2]
|
user1 = accounts[2]
|
||||||
user2 = accounts[3]
|
user2 = accounts[3]
|
||||||
user3 = accounts[4]
|
user3 = accounts[4]
|
||||||
|
user4 = accounts[4]
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should publish a dataset (create NFT + ERC20)', async () => {
|
it('should publish a dataset (create NFT + ERC20)', async () => {
|
||||||
@ -145,8 +147,6 @@ describe('Simple Publish & consume test', async () => {
|
|||||||
encryptedResponse,
|
encryptedResponse,
|
||||||
'0x' + metadataHash
|
'0x' + metadataHash
|
||||||
)
|
)
|
||||||
// const resolvedDDO = await aquarius.waitForAqua(ddo.id)
|
|
||||||
// assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')
|
|
||||||
|
|
||||||
// graph tests here
|
// graph tests here
|
||||||
await sleep(2000)
|
await sleep(2000)
|
||||||
@ -161,54 +161,6 @@ describe('Simple Publish & consume test', async () => {
|
|||||||
})
|
})
|
||||||
const queryResult = await response.json()
|
const queryResult = await response.json()
|
||||||
assert(queryResult.data.nft.id === graphNftToken)
|
assert(queryResult.data.nft.id === graphNftToken)
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
// mint 1 ERC20 and send it to the consumer
|
|
||||||
await datatoken.mint(datatokenAddress, publisherAccount, '1', consumerAccount)
|
|
||||||
// initialize provider
|
|
||||||
const initializeData = await ProviderInstance.initialize(
|
|
||||||
resolvedDDO.id,
|
|
||||||
resolvedDDO.services[0].id,
|
|
||||||
0,
|
|
||||||
consumerAccount,
|
|
||||||
providerUrl
|
|
||||||
)
|
|
||||||
const providerFees: ProviderFees = {
|
|
||||||
providerFeeAddress: initializeData.providerFee.providerFeeAddress,
|
|
||||||
providerFeeToken: initializeData.providerFee.providerFeeToken,
|
|
||||||
providerFeeAmount: initializeData.providerFee.providerFeeAmount,
|
|
||||||
v: initializeData.providerFee.v,
|
|
||||||
r: initializeData.providerFee.r,
|
|
||||||
s: initializeData.providerFee.s,
|
|
||||||
providerData: initializeData.providerFee.providerData,
|
|
||||||
validUntil: initializeData.providerFee.validUntil
|
|
||||||
}
|
|
||||||
// make the payment
|
|
||||||
const txid = await datatoken.startOrder(
|
|
||||||
datatokenAddress,
|
|
||||||
consumerAccount,
|
|
||||||
consumerAccount,
|
|
||||||
0,
|
|
||||||
providerFees
|
|
||||||
)
|
|
||||||
// get the url
|
|
||||||
const downloadURL = await ProviderInstance.getDownloadUrl(
|
|
||||||
ddo.id,
|
|
||||||
consumerAccount,
|
|
||||||
ddo.services[0].id,
|
|
||||||
0,
|
|
||||||
txid.transactionHash,
|
|
||||||
providerUrl,
|
|
||||||
web3
|
|
||||||
)
|
|
||||||
assert(downloadURL, 'Provider getDownloadUrl failed')
|
|
||||||
try {
|
|
||||||
const fileData = await downloadFile(downloadURL)
|
|
||||||
} catch (e) {
|
|
||||||
assert.fail('Download failed')
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
})
|
})
|
||||||
it('should publish and transfer an NFT', async () => {
|
it('should publish and transfer an NFT', async () => {
|
||||||
const nftParams: NftCreateData = {
|
const nftParams: NftCreateData = {
|
||||||
@ -322,7 +274,6 @@ describe('Simple Publish & consume test', async () => {
|
|||||||
providerData: web3.utils.toHex(web3.utils.asciiToHex(providerData)),
|
providerData: web3.utils.toHex(web3.utils.asciiToHex(providerData)),
|
||||||
validUntil: providerValidUntil
|
validUntil: providerValidUntil
|
||||||
}
|
}
|
||||||
console.log('setProviderFee', setProviderFee)
|
|
||||||
const orderTx = await datatoken.startOrder(
|
const orderTx = await datatoken.startOrder(
|
||||||
datatokenAddress,
|
datatokenAddress,
|
||||||
user1,
|
user1,
|
||||||
@ -330,26 +281,20 @@ describe('Simple Publish & consume test', async () => {
|
|||||||
1,
|
1,
|
||||||
setProviderFee
|
setProviderFee
|
||||||
)
|
)
|
||||||
console.log('#### order', orderTx)
|
|
||||||
const orderId = `${orderTx.transactionHash.toLocaleLowerCase()}-${datatokenAddress.toLocaleLowerCase()}-${user1.toLocaleLowerCase()}`
|
const orderId = `${orderTx.transactionHash.toLocaleLowerCase()}-${datatokenAddress.toLocaleLowerCase()}-${user1.toLocaleLowerCase()}`
|
||||||
console.log('#### orderId', orderId)
|
|
||||||
await sleep(2000)
|
|
||||||
const query = { query: `query {order(id:"${orderId}"){id, providerFee}}` }
|
const query = { query: `query {order(id:"${orderId}"){id, providerFee}}` }
|
||||||
|
|
||||||
await sleep(2000)
|
await sleep(2000)
|
||||||
const response3 = await fetch(subgraphUrl, {
|
const response = await fetch(subgraphUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(query)
|
body: JSON.stringify(query)
|
||||||
})
|
})
|
||||||
|
|
||||||
const queryResult = await response3.json()
|
const queryResult = await response.json()
|
||||||
console.log(
|
|
||||||
'#### queryResult.data.order.providerFee',
|
|
||||||
queryResult.data.order.providerFee
|
|
||||||
)
|
|
||||||
const providerFeeJSON = JSON.parse(queryResult.data.order.providerFee)
|
const providerFeeJSON = JSON.parse(queryResult.data.order.providerFee)
|
||||||
console.log('providerFeeJSON', providerFeeJSON.providerFeeAddress)
|
|
||||||
console.log('setProviderFee', setProviderFee.providerFeeAddress)
|
|
||||||
assert(
|
assert(
|
||||||
providerFeeJSON.providerFeeAddress.toLowerCase() ===
|
providerFeeJSON.providerFeeAddress.toLowerCase() ===
|
||||||
setProviderFee.providerFeeAddress.toLowerCase(),
|
setProviderFee.providerFeeAddress.toLowerCase(),
|
||||||
@ -367,101 +312,143 @@ describe('Simple Publish & consume test', async () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
// it('should save provider fees after calling reuseOrder on a using a previous txId', async () => {
|
it('should save provider fees after calling reuseOrder on a using a previous txId', async () => {
|
||||||
// const providerData = JSON.stringify({ timeout: 0 })
|
await datatoken.mint(datatokenAddress, publisherAccount, '100', user4)
|
||||||
// const providerFeeToken = ZERO_ADDRESS
|
const user4Balance = await datatoken.balance(datatokenAddress, user4)
|
||||||
// let providerFeeAmount = '90'
|
assert(user4Balance === '100', 'publisherAccount has no datatokens')
|
||||||
// let providerValidUntil = '0'
|
|
||||||
// let message = web3.utils.soliditySha3(
|
|
||||||
// { t: 'bytes', v: web3.utils.toHex(web3.utils.asciiToHex(providerData)) },
|
|
||||||
// { t: 'address', v: user3 },
|
|
||||||
// { t: 'address', v: providerFeeToken },
|
|
||||||
// { t: 'uint256', v: providerFeeAmount },
|
|
||||||
// { t: 'uint256', v: providerValidUntil }
|
|
||||||
// )
|
|
||||||
// let { v, r, s } = await signHash(web3, message, user3)
|
|
||||||
// const setInitialProviderFee: ProviderFees = {
|
|
||||||
// providerFeeAddress: user3,
|
|
||||||
// providerFeeToken,
|
|
||||||
// providerFeeAmount,
|
|
||||||
// v,
|
|
||||||
// r,
|
|
||||||
// s,
|
|
||||||
// providerData: web3.utils.toHex(web3.utils.asciiToHex(providerData)),
|
|
||||||
// validUntil: providerValidUntil
|
|
||||||
// }
|
|
||||||
// const orderTx = await datatoken.startOrder(
|
|
||||||
// datatokenAddress,
|
|
||||||
// publisherAccount,
|
|
||||||
// user2,
|
|
||||||
// 1,
|
|
||||||
// setInitialProviderFee
|
|
||||||
// )
|
|
||||||
// assert(orderTx.transactionHash, ' Failed to start order')
|
|
||||||
|
|
||||||
// // Check initial provider fee has been set correctly
|
const providerData = JSON.stringify({ timeout: 0 })
|
||||||
// const orderId = `${orderTx.transactionHash}-${datatokenAddress}-${publisherAccount}`
|
const providerFeeToken = ZERO_ADDRESS
|
||||||
// const query = {
|
let providerFeeAmount = '90'
|
||||||
// query: `query {
|
let providerValidUntil = '0'
|
||||||
// OrderReuse(id:"${orderId}"){id, providerFee}}`
|
let message = web3.utils.soliditySha3(
|
||||||
// }
|
{ t: 'bytes', v: web3.utils.toHex(web3.utils.asciiToHex(providerData)) },
|
||||||
// const response = await fetch(subgraphUrl, {
|
{ t: 'address', v: user3 },
|
||||||
// method: 'POST',
|
{ t: 'address', v: providerFeeToken },
|
||||||
// body: JSON.stringify(query)
|
{ t: 'uint256', v: providerFeeAmount },
|
||||||
// })
|
{ t: 'uint256', v: providerValidUntil }
|
||||||
// const queryResult = await response.json()
|
)
|
||||||
// assert(
|
let { v, r, s } = await signHash(web3, message, user3)
|
||||||
// queryResult.data.order.providerFee === setInitialProviderFee,
|
const setInitialProviderFee: ProviderFees = {
|
||||||
// 'Initial provider fee was not correctly set'
|
providerFeeAddress: user3,
|
||||||
// )
|
providerFeeToken,
|
||||||
|
providerFeeAmount,
|
||||||
|
v,
|
||||||
|
r,
|
||||||
|
s,
|
||||||
|
providerData: web3.utils.toHex(web3.utils.asciiToHex(providerData)),
|
||||||
|
validUntil: providerValidUntil
|
||||||
|
}
|
||||||
|
|
||||||
// providerFeeAmount = '90'
|
const orderTx = await datatoken.startOrder(
|
||||||
// providerValidUntil = '0'
|
datatokenAddress,
|
||||||
// message = web3.utils.soliditySha3(
|
user4,
|
||||||
// { t: 'bytes', v: web3.utils.toHex(web3.utils.asciiToHex(providerData)) },
|
user2,
|
||||||
// { t: 'address', v: user3 },
|
1,
|
||||||
// { t: 'address', v: providerFeeToken },
|
setInitialProviderFee
|
||||||
// { t: 'uint256', v: providerFeeAmount },
|
)
|
||||||
// { t: 'uint256', v: providerValidUntil }
|
assert(orderTx.transactionHash, 'Failed to start order')
|
||||||
// )
|
|
||||||
// const msgResult = await signHash(web3, message, user3)
|
|
||||||
// v = msgResult.v
|
|
||||||
// r = msgResult.r
|
|
||||||
// s = msgResult.s
|
|
||||||
|
|
||||||
// const setNewProviderFee: ProviderFees = {
|
// Check initial provider fee has been set correctly
|
||||||
// providerFeeAddress: user3,
|
const orderId = `${orderTx.transactionHash.toLowerCase()}-${datatokenAddress.toLowerCase()}-${user4.toLowerCase()}`
|
||||||
// providerFeeToken,
|
|
||||||
// providerFeeAmount,
|
|
||||||
// v,
|
|
||||||
// r,
|
|
||||||
// s,
|
|
||||||
// providerData: web3.utils.toHex(web3.utils.asciiToHex(providerData)),
|
|
||||||
// validUntil: providerValidUntil
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const reusedOrder = await datatoken.reuseOrder(
|
const initialQuery = {
|
||||||
// datatokenAddress,
|
query: `query {order(id:"${orderId}"){id, providerFee}}`
|
||||||
// user2,
|
}
|
||||||
// orderTx.transactionHash,
|
await sleep(2000)
|
||||||
// setNewProviderFee
|
const initialResponse = await fetch(subgraphUrl, {
|
||||||
// )
|
method: 'POST',
|
||||||
// assert(reusedOrder.events.OrderReused.event === 'OrderReused')
|
body: JSON.stringify(initialQuery)
|
||||||
// assert(reusedOrder.events.ProviderFee.event === 'ProviderFee')
|
})
|
||||||
|
const initialQueryResult = await initialResponse.json()
|
||||||
|
const initialProviderFeeJSON = JSON.parse(
|
||||||
|
initialQueryResult.data.order.providerFee
|
||||||
|
)
|
||||||
|
|
||||||
// // Check the new provider fee has been set in OrderReuse
|
assert(
|
||||||
// const query2 = {
|
initialProviderFeeJSON.providerFeeAddress.toLowerCase() ===
|
||||||
// query: `query {
|
setInitialProviderFee.providerFeeAddress.toLowerCase(),
|
||||||
// OrderReuse(id:"${reusedOrder.transactionHash}"){id, providerFee}}`
|
'Wrong initial providerFeeAddress set'
|
||||||
// }
|
)
|
||||||
// const response2 = await fetch(subgraphUrl, {
|
assert(
|
||||||
// method: 'POST',
|
initialProviderFeeJSON.providerFeeAmount.toLowerCase() ===
|
||||||
// body: JSON.stringify(query2)
|
setInitialProviderFee.providerFeeAmount.toLowerCase(),
|
||||||
// })
|
'Wrong initial providerFeeAmount set'
|
||||||
// const queryResult2 = await response2.json()
|
)
|
||||||
// assert(
|
assert(
|
||||||
// queryResult2.data.order.providerFee === setNewProviderFee,
|
initialProviderFeeJSON.providerFeeToken.toLowerCase() ===
|
||||||
// 'New provider fees have not been correctly set in OrderReuse'
|
setInitialProviderFee.providerFeeToken.toLowerCase(),
|
||||||
// )
|
'Wrong initial providerFeeToken set'
|
||||||
// })
|
)
|
||||||
|
|
||||||
|
providerFeeAmount = '990000'
|
||||||
|
providerValidUntil = '10000'
|
||||||
|
message = web3.utils.soliditySha3(
|
||||||
|
{ t: 'bytes', v: web3.utils.toHex(web3.utils.asciiToHex(providerData)) },
|
||||||
|
{ t: 'address', v: user3 },
|
||||||
|
{ t: 'address', v: providerFeeToken },
|
||||||
|
{ t: 'uint256', v: providerFeeAmount },
|
||||||
|
{ t: 'uint256', v: providerValidUntil }
|
||||||
|
)
|
||||||
|
const msgResult = await signHash(web3, message, user3)
|
||||||
|
v = msgResult.v
|
||||||
|
r = msgResult.r
|
||||||
|
s = msgResult.s
|
||||||
|
|
||||||
|
const setNewProviderFee: ProviderFees = {
|
||||||
|
providerFeeAddress: user3,
|
||||||
|
providerFeeToken,
|
||||||
|
providerFeeAmount,
|
||||||
|
v,
|
||||||
|
r,
|
||||||
|
s,
|
||||||
|
providerData: web3.utils.toHex(web3.utils.asciiToHex(providerData)),
|
||||||
|
validUntil: providerValidUntil
|
||||||
|
}
|
||||||
|
|
||||||
|
const reusedOrder = await datatoken.reuseOrder(
|
||||||
|
datatokenAddress,
|
||||||
|
user2,
|
||||||
|
orderTx.transactionHash,
|
||||||
|
setNewProviderFee
|
||||||
|
)
|
||||||
|
|
||||||
|
assert(reusedOrder.events.OrderReused.event === 'OrderReused')
|
||||||
|
assert(reusedOrder.events.ProviderFee.event === 'ProviderFee')
|
||||||
|
|
||||||
|
sleep(4000)
|
||||||
|
// Check the new provider fee has been set in OrderReuse
|
||||||
|
|
||||||
|
const reuseQuery = {
|
||||||
|
query: `query {orderReuse(id:"${reusedOrder.transactionHash}"){id, providerFee}}`
|
||||||
|
}
|
||||||
|
|
||||||
|
await sleep(2000)
|
||||||
|
const response = await fetch(subgraphUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(reuseQuery)
|
||||||
|
})
|
||||||
|
|
||||||
|
const reuseQueryResult = await response.json()
|
||||||
|
|
||||||
|
const reuseProviderFeeJSON = JSON.parse(
|
||||||
|
reuseQueryResult.data.orderReuse.providerFee
|
||||||
|
)
|
||||||
|
|
||||||
|
assert(
|
||||||
|
reuseProviderFeeJSON.providerFeeAddress.toLowerCase() ===
|
||||||
|
setNewProviderFee.providerFeeAddress.toLowerCase(),
|
||||||
|
'New providerFeeAddress set in reuse order is wrong'
|
||||||
|
)
|
||||||
|
assert(
|
||||||
|
reuseProviderFeeJSON.providerFeeAmount.toLowerCase() ===
|
||||||
|
setNewProviderFee.providerFeeAmount.toLowerCase(),
|
||||||
|
'New providerFeeAmount set in reuse order is wrong'
|
||||||
|
)
|
||||||
|
assert(
|
||||||
|
reuseProviderFeeJSON.providerFeeToken.toLowerCase() ===
|
||||||
|
setNewProviderFee.providerFeeToken.toLowerCase(),
|
||||||
|
'New providerFeeToken set in reuse order is wrong'
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user