mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
Feature/add_optimism & use graph-node 0.33.0 (#742)
* bump contracts * remove ss contracts * add optimism * fix * use upcoming barge * move deactivateMint and delete sell test * add withMint=True and delete sell test * fix lint * more fixes * more fixes
This commit is contained in:
parent
fc07962311
commit
8bc4dab920
4
.github/workflows/tests.yml
vendored
4
.github/workflows/tests.yml
vendored
@ -37,7 +37,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
repository: 'oceanprotocol/barge'
|
repository: 'oceanprotocol/barge'
|
||||||
path: 'barge'
|
path: 'barge'
|
||||||
ref: main
|
ref: feature/bump_contracts_and_subgraph
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
if: ${{ env.DOCKERHUB_PASSWORD && env.DOCKERHUB_USERNAME }}
|
if: ${{ env.DOCKERHUB_PASSWORD && env.DOCKERHUB_USERNAME }}
|
||||||
@ -51,8 +51,6 @@ jobs:
|
|||||||
working-directory: ${{ github.workspace }}/barge
|
working-directory: ${{ github.workspace }}/barge
|
||||||
run: |
|
run: |
|
||||||
bash -x start_ocean.sh --with-thegraph --skip-subgraph-deploy --no-dashboard 2>&1 > start_ocean.log &
|
bash -x start_ocean.sh --with-thegraph --skip-subgraph-deploy --no-dashboard 2>&1 > start_ocean.log &
|
||||||
env:
|
|
||||||
CONTRACTS_VERSION: predictoor3
|
|
||||||
|
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
|
|
||||||
|
651
package-lock.json
generated
651
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -19,6 +19,8 @@
|
|||||||
"quickstart:bsc": "node ./scripts/generatenetworkssubgraphs.js bsc && npm run codegen && npm run create:local && npm run deploy:local",
|
"quickstart:bsc": "node ./scripts/generatenetworkssubgraphs.js bsc && npm run codegen && npm run create:local && npm run deploy:local",
|
||||||
"quickstart:oasis_saphire_testnet": "node ./scripts/generatenetworkssubgraphs.js oasis_saphire_testnet && npm run codegen && npm run create:local && npm run deploy:local",
|
"quickstart:oasis_saphire_testnet": "node ./scripts/generatenetworkssubgraphs.js oasis_saphire_testnet && npm run codegen && npm run create:local && npm run deploy:local",
|
||||||
"quickstart:oasis_saphire": "node ./scripts/generatenetworkssubgraphs.js oasis_saphire && npm run codegen && npm run create:local && npm run deploy:local",
|
"quickstart:oasis_saphire": "node ./scripts/generatenetworkssubgraphs.js oasis_saphire && npm run codegen && npm run create:local && npm run deploy:local",
|
||||||
|
"quickstart:optimism": "node ./scripts/generatenetworkssubgraphs.js optimism && npm run codegen && npm run create:local && npm run deploy:local",
|
||||||
|
"quickstart:optimism_sepolia": "node ./scripts/generatenetworkssubgraphs.js optimism_sepolia && npm run codegen && npm run create:local && npm run deploy:local",
|
||||||
"create:thegraph": "graph create oceanprotocol/ocean-subgraph --node https://api.thegraph.com/deploy/",
|
"create:thegraph": "graph create oceanprotocol/ocean-subgraph --node https://api.thegraph.com/deploy/",
|
||||||
"create:local": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
|
"create:local": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
|
||||||
"create:local-barge": "graph create oceanprotocol/ocean-subgraph --node http://172.15.0.15:8020",
|
"create:local-barge": "graph create oceanprotocol/ocean-subgraph --node http://172.15.0.15:8020",
|
||||||
@ -79,7 +81,7 @@
|
|||||||
"typescript": "^5.2.2"
|
"typescript": "^5.2.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@oceanprotocol/contracts": "^2.0.2",
|
"@oceanprotocol/contracts": "^2.0.3",
|
||||||
"@oceanprotocol/lib": "^2.7.0",
|
"@oceanprotocol/lib": "^2.7.0",
|
||||||
"cross-fetch": "^3.1.6",
|
"cross-fetch": "^3.1.6",
|
||||||
"ethereumjs-util": "^7.1.5"
|
"ethereumjs-util": "^7.1.5"
|
||||||
|
@ -403,7 +403,6 @@ type Template @entity{
|
|||||||
id: ID!
|
id: ID!
|
||||||
fixedRateTemplates: [String!]
|
fixedRateTemplates: [String!]
|
||||||
dispenserTemplates: [String!]
|
dispenserTemplates: [String!]
|
||||||
ssTemplates: [String!]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Not tracking allocationToId or idToAllocation
|
# Not tracking allocationToId or idToAllocation
|
||||||
|
@ -3,8 +3,6 @@ import {
|
|||||||
TokenRemoved,
|
TokenRemoved,
|
||||||
OPCFeeChanged,
|
OPCFeeChanged,
|
||||||
FactoryRouter,
|
FactoryRouter,
|
||||||
SSContractAdded,
|
|
||||||
SSContractRemoved,
|
|
||||||
FixedRateContractAdded,
|
FixedRateContractAdded,
|
||||||
FixedRateContractRemoved,
|
FixedRateContractRemoved,
|
||||||
DispenserContractAdded,
|
DispenserContractAdded,
|
||||||
@ -91,32 +89,6 @@ export function handleTokenRemoved(event: TokenRemoved): void {
|
|||||||
opc.approvedTokens = newList
|
opc.approvedTokens = newList
|
||||||
opc.save()
|
opc.save()
|
||||||
}
|
}
|
||||||
export function handleSSContractAdded(event: SSContractAdded): void {
|
|
||||||
// add token to approvedTokens
|
|
||||||
const templates = getTemplates()
|
|
||||||
let existingContracts: string[]
|
|
||||||
if (!templates.ssTemplates) existingContracts = []
|
|
||||||
else existingContracts = templates.ssTemplates as string[]
|
|
||||||
if (!existingContracts.includes(event.params.contractAddress.toHexString()))
|
|
||||||
existingContracts.push(event.params.contractAddress.toHexString())
|
|
||||||
templates.ssTemplates = existingContracts
|
|
||||||
templates.save()
|
|
||||||
}
|
|
||||||
export function handleSSContractRemoved(event: SSContractRemoved): void {
|
|
||||||
const templates = getTemplates()
|
|
||||||
const newList: string[] = []
|
|
||||||
let existingContracts: string[]
|
|
||||||
if (!templates.ssTemplates) existingContracts = []
|
|
||||||
else existingContracts = templates.ssTemplates as string[]
|
|
||||||
if (!existingContracts || existingContracts.length < 1) return
|
|
||||||
while (existingContracts.length > 0) {
|
|
||||||
const role = existingContracts.shift().toString()
|
|
||||||
if (!role) break
|
|
||||||
if (role != event.params.contractAddress.toHexString()) newList.push(role)
|
|
||||||
}
|
|
||||||
templates.ssTemplates = newList
|
|
||||||
templates.save()
|
|
||||||
}
|
|
||||||
|
|
||||||
export function handleFixedRateContractAdded(
|
export function handleFixedRateContractAdded(
|
||||||
event: FixedRateContractAdded
|
event: FixedRateContractAdded
|
||||||
|
@ -52,6 +52,11 @@ export function updateFixedRateExchangeSupply(
|
|||||||
fixedRateDetails.value.value8.toBigDecimal(),
|
fixedRateDetails.value.value8.toBigDecimal(),
|
||||||
baseToken.decimals
|
baseToken.decimals
|
||||||
)
|
)
|
||||||
|
// update withMint state
|
||||||
|
fixedRateExchange.withMint = fixedRateDetails.value.value11
|
||||||
|
|
||||||
|
// update active state
|
||||||
|
fixedRateExchange.active = fixedRateDetails.value.value6
|
||||||
fixedRateExchange.save()
|
fixedRateExchange.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,10 +268,6 @@ dataSources:
|
|||||||
handler: handleTokenRemoved
|
handler: handleTokenRemoved
|
||||||
- event: OPCFeeChanged(indexed address,uint256,uint256,uint256,uint256)
|
- event: OPCFeeChanged(indexed address,uint256,uint256,uint256,uint256)
|
||||||
handler: handleOPCFeeChanged
|
handler: handleOPCFeeChanged
|
||||||
- event: SSContractAdded(indexed address,indexed address)
|
|
||||||
handler: handleSSContractAdded
|
|
||||||
- event: SSContractRemoved(indexed address,indexed address)
|
|
||||||
handler: handleSSContractRemoved
|
|
||||||
- event: FixedRateContractAdded(indexed address,indexed address)
|
- event: FixedRateContractAdded(indexed address,indexed address)
|
||||||
handler: handleFixedRateContractAdded
|
handler: handleFixedRateContractAdded
|
||||||
- event: FixedRateContractRemoved(indexed address,indexed address)
|
- event: FixedRateContractRemoved(indexed address,indexed address)
|
||||||
|
@ -44,7 +44,7 @@ describe('Fixed Rate Exchange tests', async () => {
|
|||||||
const publishMarketSwapFee = '0.003'
|
const publishMarketSwapFee = '0.003'
|
||||||
const templateIndex = 1
|
const templateIndex = 1
|
||||||
const dtAmount = '10'
|
const dtAmount = '10'
|
||||||
const datatoken = new Datatoken(web3, 8996)
|
// const datatoken = new Datatoken(web3, 8996)
|
||||||
let datatokenAddress: string
|
let datatokenAddress: string
|
||||||
let fixedRateAddress: string
|
let fixedRateAddress: string
|
||||||
let baseTokenAddress: string
|
let baseTokenAddress: string
|
||||||
@ -108,7 +108,7 @@ describe('Fixed Rate Exchange tests', async () => {
|
|||||||
fixedRate: price,
|
fixedRate: price,
|
||||||
marketFee: publishMarketSwapFee,
|
marketFee: publishMarketSwapFee,
|
||||||
allowedConsumer: ZERO_ADDRESS,
|
allowedConsumer: ZERO_ADDRESS,
|
||||||
withMint: false
|
withMint: true
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await Factory.createNftWithDatatokenWithFixedRate(
|
const result = await Factory.createNftWithDatatokenWithFixedRate(
|
||||||
@ -356,7 +356,8 @@ describe('Fixed Rate Exchange tests', async () => {
|
|||||||
'incorrect value for: baseToken.id'
|
'incorrect value for: baseToken.id'
|
||||||
)
|
)
|
||||||
assert(
|
assert(
|
||||||
fixed.datatokenSupply === '0',
|
fixed.datatokenSupply ===
|
||||||
|
'115792089237316195423570985008687900000000000000000000000000',
|
||||||
'incorrect value for: datatokenSupply'
|
'incorrect value for: datatokenSupply'
|
||||||
)
|
)
|
||||||
assert(
|
assert(
|
||||||
@ -378,7 +379,7 @@ describe('Fixed Rate Exchange tests', async () => {
|
|||||||
fixed.allowedSwapper === ZERO_ADDRESS,
|
fixed.allowedSwapper === ZERO_ADDRESS,
|
||||||
'incorrect value for: allowedSwapper'
|
'incorrect value for: allowedSwapper'
|
||||||
)
|
)
|
||||||
assert(fixed.withMint === null, 'incorrect value for: withMint')
|
assert(fixed.withMint === true, 'incorrect value for: withMint')
|
||||||
assert(fixed.isMinter === null, 'incorrect value for: isMinter')
|
assert(fixed.isMinter === null, 'incorrect value for: isMinter')
|
||||||
assert(fixed.updates, 'incorrect value for: updates.id')
|
assert(fixed.updates, 'incorrect value for: updates.id')
|
||||||
assert(fixed.swaps, 'incorrect value for: swaps')
|
assert(fixed.swaps, 'incorrect value for: swaps')
|
||||||
@ -496,125 +497,6 @@ describe('Fixed Rate Exchange tests', async () => {
|
|||||||
'incorrect value: 3nd eventIndex'
|
'incorrect value: 3nd eventIndex'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
it('Deactivates exchange', async () => {
|
|
||||||
const deactiveQuery = {
|
|
||||||
query: `query {fixedRateExchange(id: "${fixedRateId}"){active, eventIndex}}`
|
|
||||||
}
|
|
||||||
|
|
||||||
const initialResponse = await fetch(subgraphUrl, {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(deactiveQuery)
|
|
||||||
})
|
|
||||||
const initialActive = (await initialResponse.json()).data.fixedRateExchange
|
|
||||||
.active
|
|
||||||
assert(initialActive === true, 'incorrect value for: initialActive')
|
|
||||||
|
|
||||||
// Deactivate exchange
|
|
||||||
await fixedRate.deactivate(publisher, exchangeId)
|
|
||||||
await sleep(sleepMs)
|
|
||||||
|
|
||||||
// Check the updated value for active
|
|
||||||
const updatedResponse = await fetch(subgraphUrl, {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(deactiveQuery)
|
|
||||||
})
|
|
||||||
const updatedActive = (await updatedResponse.json()).data.fixedRateExchange
|
|
||||||
|
|
||||||
assert(updatedActive.active === false, 'incorrect value for: updatedActive')
|
|
||||||
assert(
|
|
||||||
updatedActive.eventIndex !== null && updatedActive.eventIndex > 0,
|
|
||||||
'incorrect value: eventIndex'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Activates exchange', async () => {
|
|
||||||
const activeQuery = {
|
|
||||||
query: `query {fixedRateExchange(id: "${fixedRateId}"){active, eventIndex}}`
|
|
||||||
}
|
|
||||||
const initialResponse = await fetch(subgraphUrl, {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(activeQuery)
|
|
||||||
})
|
|
||||||
const initialActive = (await initialResponse.json()).data.fixedRateExchange
|
|
||||||
.active
|
|
||||||
assert(initialActive === false, 'incorrect value for: initialActive')
|
|
||||||
|
|
||||||
// Activate exchange
|
|
||||||
await fixedRate.activate(publisher, exchangeId)
|
|
||||||
await sleep(sleepMs)
|
|
||||||
|
|
||||||
// Check the updated value for active
|
|
||||||
const updatedResponse = await fetch(subgraphUrl, {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(activeQuery)
|
|
||||||
})
|
|
||||||
const updatedActive = (await updatedResponse.json()).data.fixedRateExchange
|
|
||||||
assert(updatedActive.active === true, 'incorrect value for: updatedActive')
|
|
||||||
assert(
|
|
||||||
updatedActive.eventIndex !== null && updatedActive.eventIndex > 0,
|
|
||||||
'incorrect value: eventIndex'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Activate Minting', async () => {
|
|
||||||
const mintingQuery = {
|
|
||||||
query: `query {fixedRateExchange(id: "${fixedRateId}"){withMint, eventIndex}}`
|
|
||||||
}
|
|
||||||
const initialResponse = await fetch(subgraphUrl, {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(mintingQuery)
|
|
||||||
})
|
|
||||||
const initialMint = (await initialResponse.json()).data.fixedRateExchange
|
|
||||||
.withMint
|
|
||||||
assert(initialMint === null, 'incorrect value for: initialMint')
|
|
||||||
|
|
||||||
// Activate minting
|
|
||||||
const tx = await fixedRate.activateMint(publisher, exchangeId)
|
|
||||||
await sleep(sleepMs)
|
|
||||||
|
|
||||||
// Check the updated value for active
|
|
||||||
const updatedResponse = await fetch(subgraphUrl, {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(mintingQuery)
|
|
||||||
})
|
|
||||||
|
|
||||||
const updatedMint = (await updatedResponse.json()).data.fixedRateExchange
|
|
||||||
assert(updatedMint.withMint === true, 'incorrect value for: updatedMint')
|
|
||||||
assert(
|
|
||||||
updatedMint.eventIndex === tx.events.ExchangeMintStateChanged.logIndex,
|
|
||||||
'incorrect value for: eventIndex'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Deactivate Minting', async () => {
|
|
||||||
const mintingQuery = {
|
|
||||||
query: `query {fixedRateExchange(id: "${fixedRateId}"){withMint, eventIndex}}`
|
|
||||||
}
|
|
||||||
const initialResponse = await fetch(subgraphUrl, {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(mintingQuery)
|
|
||||||
})
|
|
||||||
const initialMint = (await initialResponse.json()).data.fixedRateExchange
|
|
||||||
.withMint
|
|
||||||
assert(initialMint === true, 'incorrect value for: initialMint')
|
|
||||||
|
|
||||||
// Activate minting
|
|
||||||
const tx = await fixedRate.deactivateMint(publisher, exchangeId)
|
|
||||||
await sleep(sleepMs)
|
|
||||||
|
|
||||||
// Check the updated value for active
|
|
||||||
const updatedResponse = await fetch(subgraphUrl, {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(mintingQuery)
|
|
||||||
})
|
|
||||||
|
|
||||||
const updatedMint = (await updatedResponse.json()).data.fixedRateExchange
|
|
||||||
assert(updatedMint.withMint === false, 'incorrect value for: updatedMint')
|
|
||||||
assert(
|
|
||||||
updatedMint.eventIndex === tx.events.ExchangeMintStateChanged.logIndex,
|
|
||||||
'incorrect value for: eventIndex'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('User1 buys a datatoken', async () => {
|
it('User1 buys a datatoken', async () => {
|
||||||
const swapsQuery = {
|
const swapsQuery = {
|
||||||
@ -721,57 +603,63 @@ describe('Fixed Rate Exchange tests', async () => {
|
|||||||
assert(swaps.eventIndex === tx.logIndex, 'incorrect value for: eventIndex')
|
assert(swaps.eventIndex === tx.logIndex, 'incorrect value for: eventIndex')
|
||||||
assert(swaps.__typename === 'FixedRateExchangeSwap', 'incorrect __typename')
|
assert(swaps.__typename === 'FixedRateExchangeSwap', 'incorrect __typename')
|
||||||
})
|
})
|
||||||
it('User1 sells a datatoken', async () => {
|
|
||||||
await datatoken.approve(datatokenAddress, fixedRateAddress, dtAmount, user1)
|
it('Deactivate Minting', async () => {
|
||||||
const tx = (await fixedRate.sellDatatokens(user1, exchangeId, '10', '9'))
|
const mintingQuery = {
|
||||||
.events?.Swapped
|
query: `query {fixedRateExchange(id: "${fixedRateId}"){withMint, eventIndex}}`
|
||||||
const oceanFeeAmount = web3.utils.fromWei(
|
|
||||||
new BN(tx.returnValues.oceanFeeAmount)
|
|
||||||
)
|
|
||||||
assert(tx != null)
|
|
||||||
await sleep(sleepMs)
|
|
||||||
const swapsQuery = {
|
|
||||||
query: `query {fixedRateExchange(id: "${fixedRateId}"){
|
|
||||||
swaps(orderBy: createdTimestamp, orderDirection: desc){
|
|
||||||
id
|
|
||||||
exchangeId{id}
|
|
||||||
by{id}
|
|
||||||
baseTokenAmount
|
|
||||||
dataTokenAmount
|
|
||||||
block
|
|
||||||
createdTimestamp
|
|
||||||
tx
|
|
||||||
eventIndex
|
|
||||||
oceanFeeAmount
|
|
||||||
__typename
|
|
||||||
}
|
|
||||||
}}`
|
|
||||||
}
|
}
|
||||||
// Check initial swaps
|
const initialResponse = await fetch(subgraphUrl, {
|
||||||
const response = await fetch(subgraphUrl, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(swapsQuery)
|
body: JSON.stringify(mintingQuery)
|
||||||
})
|
})
|
||||||
const swaps = (await response.json()).data.fixedRateExchange.swaps[0]
|
const initialMint = (await initialResponse.json()).data.fixedRateExchange
|
||||||
const swappedAmount = web3.utils.fromWei(
|
.withMint
|
||||||
new BN(tx.returnValues.baseTokenSwappedAmount)
|
assert(initialMint === true, 'incorrect value for: initialMint')
|
||||||
)
|
|
||||||
|
// Activate minting
|
||||||
|
const tx = await fixedRate.deactivateMint(publisher, exchangeId)
|
||||||
|
await sleep(sleepMs)
|
||||||
|
|
||||||
|
// Check the updated value for active
|
||||||
|
const updatedResponse = await fetch(subgraphUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(mintingQuery)
|
||||||
|
})
|
||||||
|
|
||||||
|
const updatedMint = (await updatedResponse.json()).data.fixedRateExchange
|
||||||
|
assert(updatedMint.withMint === false, 'incorrect value for: updatedMint')
|
||||||
assert(
|
assert(
|
||||||
swaps.id ===
|
updatedMint.eventIndex === tx.events.ExchangeMintStateChanged.logIndex,
|
||||||
`${tx.transactionHash}-${fixedRateId}-${tx.logIndex.toFixed(1)}`,
|
'incorrect value for: eventIndex'
|
||||||
'incorrect: id'
|
)
|
||||||
|
})
|
||||||
|
it('Activate Minting', async () => {
|
||||||
|
const mintingQuery = {
|
||||||
|
query: `query {fixedRateExchange(id: "${fixedRateId}"){withMint, eventIndex}}`
|
||||||
|
}
|
||||||
|
const initialResponse = await fetch(subgraphUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(mintingQuery)
|
||||||
|
})
|
||||||
|
const initialMint = (await initialResponse.json()).data.fixedRateExchange
|
||||||
|
.withMint
|
||||||
|
assert(initialMint === false, 'incorrect value for: initialMint')
|
||||||
|
|
||||||
|
// Activate minting
|
||||||
|
const tx = await fixedRate.activateMint(publisher, exchangeId)
|
||||||
|
await sleep(sleepMs)
|
||||||
|
|
||||||
|
// Check the updated value for active
|
||||||
|
const updatedResponse = await fetch(subgraphUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(mintingQuery)
|
||||||
|
})
|
||||||
|
const updatedMint = (await updatedResponse.json()).data.fixedRateExchange
|
||||||
|
assert(updatedMint.withMint === true, 'incorrect value for: updatedMint')
|
||||||
|
assert(
|
||||||
|
updatedMint.eventIndex === tx.events.ExchangeMintStateChanged.logIndex,
|
||||||
|
'incorrect value for: eventIndex'
|
||||||
)
|
)
|
||||||
assert(swaps.exchangeId.id === fixedRateId, 'incorrect: exchangeId')
|
|
||||||
assert(swaps.by.id === user1, 'incorrect value for: id')
|
|
||||||
assert(swaps.baseTokenAmount === swappedAmount, 'incorrect baseTokenAmount')
|
|
||||||
assert(swaps.dataTokenAmount === dtAmount, 'incorrect: dataTokenAmount')
|
|
||||||
assert(swaps.block === tx.blockNumber, 'incorrect value for: block')
|
|
||||||
assert(swaps.createdTimestamp >= time, 'incorrect: createdTimestamp')
|
|
||||||
assert(swaps.createdTimestamp < time + 25, 'incorrect: createdTimestamp 2')
|
|
||||||
assert(swaps.oceanFeeAmount === oceanFeeAmount, 'incorrect: oceanFeeAmount')
|
|
||||||
assert(swaps.tx === tx.transactionHash, 'incorrect value for: tx')
|
|
||||||
assert(swaps.eventIndex === tx.logIndex, 'incorrect value for: eventIndex')
|
|
||||||
assert(swaps.__typename === 'FixedRateExchangeSwap', 'incorrect __typename')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Updates allowed swapper', async () => {
|
it('Updates allowed swapper', async () => {
|
||||||
@ -810,4 +698,63 @@ describe('Fixed Rate Exchange tests', async () => {
|
|||||||
'incorrect value for: eventIndex'
|
'incorrect value for: eventIndex'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
it('Deactivates exchange', async () => {
|
||||||
|
const deactiveQuery = {
|
||||||
|
query: `query {fixedRateExchange(id: "${fixedRateId}"){active, eventIndex}}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialResponse = await fetch(subgraphUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(deactiveQuery)
|
||||||
|
})
|
||||||
|
const initialActive = (await initialResponse.json()).data.fixedRateExchange
|
||||||
|
.active
|
||||||
|
assert(initialActive === true, 'incorrect value for: initialActive')
|
||||||
|
|
||||||
|
// Deactivate exchange
|
||||||
|
await fixedRate.deactivate(publisher, exchangeId)
|
||||||
|
await sleep(sleepMs)
|
||||||
|
|
||||||
|
// Check the updated value for active
|
||||||
|
const updatedResponse = await fetch(subgraphUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(deactiveQuery)
|
||||||
|
})
|
||||||
|
const updatedActive = (await updatedResponse.json()).data.fixedRateExchange
|
||||||
|
|
||||||
|
assert(updatedActive.active === false, 'incorrect value for: updatedActive')
|
||||||
|
assert(
|
||||||
|
updatedActive.eventIndex !== null && updatedActive.eventIndex >= 0,
|
||||||
|
'incorrect value: eventIndex'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Activates exchange', async () => {
|
||||||
|
const activeQuery = {
|
||||||
|
query: `query {fixedRateExchange(id: "${fixedRateId}"){active, eventIndex}}`
|
||||||
|
}
|
||||||
|
const initialResponse = await fetch(subgraphUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(activeQuery)
|
||||||
|
})
|
||||||
|
const initialActive = (await initialResponse.json()).data.fixedRateExchange
|
||||||
|
.active
|
||||||
|
assert(initialActive === false, 'incorrect value for: initialActive')
|
||||||
|
|
||||||
|
// Activate exchange
|
||||||
|
await fixedRate.activate(publisher, exchangeId)
|
||||||
|
await sleep(sleepMs)
|
||||||
|
|
||||||
|
// Check the updated value for active
|
||||||
|
const updatedResponse = await fetch(subgraphUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(activeQuery)
|
||||||
|
})
|
||||||
|
const updatedActive = (await updatedResponse.json()).data.fixedRateExchange
|
||||||
|
assert(updatedActive.active === true, 'incorrect value for: updatedActive')
|
||||||
|
assert(
|
||||||
|
updatedActive.eventIndex !== null && updatedActive.eventIndex >= 0,
|
||||||
|
'incorrect value: eventIndex'
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -64,7 +64,7 @@ describe('User tests', async () => {
|
|||||||
const publishMarketSwapFee = '0.003'
|
const publishMarketSwapFee = '0.003'
|
||||||
const templateIndex = 1
|
const templateIndex = 1
|
||||||
const dtAmount = '10'
|
const dtAmount = '10'
|
||||||
const datatoken = new Datatoken(web3, 8996)
|
// const datatoken = new Datatoken(web3, 8996)
|
||||||
let datatokenAddress: string
|
let datatokenAddress: string
|
||||||
let fixedRateAddress: string
|
let fixedRateAddress: string
|
||||||
let baseTokenAddress: string
|
let baseTokenAddress: string
|
||||||
@ -123,7 +123,7 @@ describe('User tests', async () => {
|
|||||||
fixedRate: price,
|
fixedRate: price,
|
||||||
marketFee: publishMarketSwapFee,
|
marketFee: publishMarketSwapFee,
|
||||||
allowedConsumer: ZERO_ADDRESS,
|
allowedConsumer: ZERO_ADDRESS,
|
||||||
withMint: false
|
withMint: true
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await Factory.createNftWithDatatokenWithFixedRate(
|
const result = await Factory.createNftWithDatatokenWithFixedRate(
|
||||||
@ -196,27 +196,6 @@ describe('User tests', async () => {
|
|||||||
assert(user.totalSales === '0', 'incorrect value for: totalSales')
|
assert(user.totalSales === '0', 'incorrect value for: totalSales')
|
||||||
assert(user.__typename === 'User', 'incorrect value for: __typename')
|
assert(user.__typename === 'User', 'incorrect value for: __typename')
|
||||||
})
|
})
|
||||||
it('User1 sells a datatoken', async () => {
|
|
||||||
const initialUser = await userQuery(user1)
|
|
||||||
await datatoken.approve(datatokenAddress, fixedRateAddress, dtAmount, user1)
|
|
||||||
const tx = (await fixedRate.sellDatatokens(user1, exchangeId, '10', '9'))
|
|
||||||
.events?.Swapped
|
|
||||||
|
|
||||||
assert(tx != null)
|
|
||||||
const user = await userQuery(user1)
|
|
||||||
|
|
||||||
assert(user.id === user1, 'incorrect value for: id')
|
|
||||||
assert(user.tokenBalancesOwned.length === 0, 'incorrect tokenBalancesOwned')
|
|
||||||
assert(user.orders.length === 0, 'incorrect value for: orders')
|
|
||||||
assert(
|
|
||||||
user.freSwaps.length === initialUser.freSwaps.length,
|
|
||||||
'incorrect value for: freSwaps'
|
|
||||||
)
|
|
||||||
assert(user.totalOrders === '0', 'incorrect value for: totalOrders')
|
|
||||||
assert(user.totalSales === '0', 'incorrect value for: totalSales')
|
|
||||||
assert(user.__typename === 'User', 'incorrect value for: __typename')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Check user fields after publishing & ordering a datatoken', async () => {
|
it('Check user fields after publishing & ordering a datatoken', async () => {
|
||||||
// Start with publishing a new datatoken
|
// Start with publishing a new datatoken
|
||||||
const nftParams: NftCreateData = {
|
const nftParams: NftCreateData = {
|
||||||
|
Loading…
Reference in New Issue
Block a user