mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
e1df119197
* Store eventIndex. * Changed in veDelegation. Removed import of String. * linter. * Removed tx hash. * Revert some tweaks. * added logIndex. * converted to big int. * 0 -> BigInt.zero(). * Added eventIndex to template and OPC. * updated tweak * updated tweak2 * Added eventIndex in tests. * revert. * Added eventIndex for TokenCreated and NFTCreated events. Increase time sleep for graphql request. * Changed position of eventIndex in entity. * Added eventIndex for order events and for dt events. Added new test commands in package.json. * Added eventIndex for NFT Update events. * Added eventIndex for dispenser. * Modified dispenser tests. * Reverted sleep secs. Updated tests. * Updated dispenser tests. Added eventIndex for FRE. * Added eventIndex in df rewards. * Updated Ve with eventIndex. * Updating order id with event index. * Updated @ocean/lib with multichain version. * Updated to number type. * Updated tests for order. * some changes. * Fix dt tests. Added logs for provider fee. Need fix for Simple publish and consume tests. * Problem raised by retrieving order event index in provider fee event handler. * Added function for searching the right order. * Debug order with provider fee. * Removed console logs. * Added debug logs. * Hardcoded eventIndex just for testing. * Paste logs from graph node. * added extra sleep in test. * fixed command. * Added comments. Modified util function for Order Reuse. * Added more logs and other tweaks. * fixed command for docker logs. * Added more logs. * Converted to lowercase. * Removed condition just for test. * Added more logs. Order is not null. * Call getOrder. * Added verification back. * converted to hex and add toString. * Pass toString as param. * Added ethereumjs util. * replaced with ==. * Refactored logic. * Print event index. * added more logs of event index. * Modified tweaks and asserts. * Added log for reuse order. * updates. * Reverted changes. * Added check for eventIndex == 0. * Enhanced the code. Replaced while with for. * Added more logs for reuse test. * added another condition. * Added logs in tests. Removed redundant condition. * Added more logs to test. * Fixed typo. * still debugging * Refactored code. * Getting closer. * Fix tests for orders part. Removed logs. * Removed more logs. * Fix DT tests related to order. * Implemented Publishing Market Fee event handler. Added test. * Added consume market fee handler. Test consume market fee handler. * Fixed tests for fees. Added TODOs. * Generated ID with eventIndex in ficed rate. Added assert errors messages. * Added FRE tests to workflow. * Generated dispenser transaction with event index. * Fixed dispenser tests. * Add event index for NftUpdate entity ID. * Changed IDs for VeDelegation and VeAllocationUpdate. * Added full test suite to workflow. * Fixed nft transfer ID. * print blocks. * test just dt and ending test to see the last block. * Added df test. * Added dispenser test. * Added FRE test. * Added NFT test. * Added simple publish consume test. * Added simple subgraph test. * Added users test. * Added ve test. * Increased sleep time. * commented delegation test. * respect lint * Fixed ending tests. Removed commented code. Brought back test suite. * Print values from failing tests. Updated mappings. * Rollback changes in veDelegation and veUtils. Added more prints for debug in tests. * Removed veDelegation creation record. * Rollback to the approach for veDelegation like it is in main. * Removed prints. Match changes with main. * Removed -1 from last block. * Added prints for eventIndex. Fixed some suggestions. * Fixed veDelegation. * Removed prints.
164 lines
4.6 KiB
TypeScript
164 lines
4.6 KiB
TypeScript
import {
|
|
DatatokenCreateParams,
|
|
Nft,
|
|
NftFactory,
|
|
NftCreateData,
|
|
sleep
|
|
} from '@oceanprotocol/lib'
|
|
import { assert } from 'chai'
|
|
import Web3 from 'web3'
|
|
import { homedir } from 'os'
|
|
import fs from 'fs'
|
|
import { fetch } from 'cross-fetch'
|
|
|
|
const data = JSON.parse(
|
|
fs.readFileSync(
|
|
process.env.ADDRESS_FILE ||
|
|
`${homedir}/.ocean/ocean-contracts/artifacts/address.json`,
|
|
'utf8'
|
|
)
|
|
)
|
|
|
|
const addresses = data.development
|
|
const web3 = new Web3('http://127.0.0.1:8545')
|
|
|
|
const subgraphUrl =
|
|
'http://127.0.0.1:9000/subgraphs/name/oceanprotocol/ocean-subgraph'
|
|
|
|
describe('Tests coverage without provider/aquarius', async () => {
|
|
let nft: Nft
|
|
let Factory: NftFactory
|
|
let accounts: string[]
|
|
let publisherAccount: string
|
|
let newOwnerAccount: string
|
|
let time: number
|
|
|
|
before(async () => {
|
|
nft = new Nft(web3)
|
|
Factory = new NftFactory(addresses.ERC721Factory, web3)
|
|
accounts = await web3.eth.getAccounts()
|
|
publisherAccount = accounts[0]
|
|
newOwnerAccount = accounts[1].toLowerCase()
|
|
const date = new Date()
|
|
time = Math.floor(date.getTime() / 1000)
|
|
})
|
|
|
|
it('should publish a dataset (create NFT + ERC20)', async () => {
|
|
const nftParams: NftCreateData = {
|
|
name: 'testNFT',
|
|
symbol: 'TST',
|
|
templateIndex: 1,
|
|
tokenURI: '',
|
|
transferable: true,
|
|
owner: publisherAccount
|
|
}
|
|
const erc20Params: DatatokenCreateParams = {
|
|
templateIndex: 1,
|
|
cap: '100000',
|
|
feeAmount: '0',
|
|
paymentCollector: '0x0000000000000000000000000000000000000000',
|
|
feeToken: '0x0000000000000000000000000000000000000000',
|
|
minter: publisherAccount,
|
|
mpFeeAddress: '0x0000000000000000000000000000000000000000'
|
|
}
|
|
const result = await Factory.createNftWithDatatoken(
|
|
publisherAccount,
|
|
nftParams,
|
|
erc20Params
|
|
)
|
|
const erc721Address = result.events.NFTCreated.returnValues[0]
|
|
|
|
// graph tests here
|
|
await sleep(3000)
|
|
const graphNftToken = erc721Address.toLowerCase()
|
|
const query = {
|
|
query: `query {
|
|
nft(id:"${graphNftToken}"){symbol,id,eventIndex}}`
|
|
}
|
|
const response = await fetch(subgraphUrl, {
|
|
method: 'POST',
|
|
body: JSON.stringify(query)
|
|
})
|
|
await sleep(3000)
|
|
const queryResult = await response.json()
|
|
assert(queryResult.data.nft.id === graphNftToken)
|
|
assert(
|
|
queryResult.data.nft.eventIndex !== null &&
|
|
queryResult.data.nft.eventIndex > 0
|
|
)
|
|
})
|
|
|
|
it('should publish and transfer an NFT', async () => {
|
|
const nftParams: NftCreateData = {
|
|
name: 'testNFT',
|
|
symbol: 'TST',
|
|
templateIndex: 1,
|
|
tokenURI: '',
|
|
transferable: true,
|
|
owner: publisherAccount
|
|
}
|
|
const erc20Params: DatatokenCreateParams = {
|
|
templateIndex: 1,
|
|
cap: '100000',
|
|
feeAmount: '0',
|
|
paymentCollector: '0x0000000000000000000000000000000000000000',
|
|
feeToken: '0x0000000000000000000000000000000000000000',
|
|
minter: publisherAccount,
|
|
mpFeeAddress: '0x0000000000000000000000000000000000000000'
|
|
}
|
|
const result = await Factory.createNftWithDatatoken(
|
|
publisherAccount,
|
|
nftParams,
|
|
erc20Params
|
|
)
|
|
await sleep(3000)
|
|
const erc721Address = result.events.NFTCreated.returnValues[0]
|
|
const nftAddress = erc721Address.toLowerCase()
|
|
|
|
// Transfer the NFT
|
|
const tx = await nft.transferNft(
|
|
nftAddress,
|
|
publisherAccount,
|
|
newOwnerAccount
|
|
)
|
|
|
|
await sleep(3000)
|
|
const query2 = {
|
|
query: `query {
|
|
nft(id:"${nftAddress}"){
|
|
symbol,
|
|
id,
|
|
owner{id},
|
|
transferable,
|
|
transferHistory(orderBy: timestamp, orderDirection: desc){id,nft,oldOwner,newOwner,txId,eventIndex,timestamp,block}
|
|
}}`
|
|
}
|
|
const response = await fetch(subgraphUrl, {
|
|
method: 'POST',
|
|
body: JSON.stringify(query2)
|
|
})
|
|
await sleep(3000)
|
|
const queryResult = await response.json()
|
|
const transferHistory = queryResult.data.nft.transferHistory[0]
|
|
|
|
assert(queryResult.data.nft.owner.id === newOwnerAccount)
|
|
assert(
|
|
transferHistory.id ===
|
|
`${nftAddress}-${
|
|
tx.transactionHash
|
|
}-${tx.events.Transfer.logIndex.toFixed(1)}`,
|
|
'Invalid transferHistory Id'
|
|
)
|
|
assert(transferHistory.txId === tx.transactionHash, 'invalid txId')
|
|
assert(
|
|
transferHistory.eventIndex === tx.events.Transfer.logIndex,
|
|
'invalid eventIndex'
|
|
)
|
|
assert(transferHistory.timestamp)
|
|
|
|
assert(transferHistory.timestamp >= time - 500, 'incorrect value timestamp')
|
|
assert(transferHistory.timestamp < time + 500, 'incorrect value timestamp')
|
|
assert(transferHistory.block === tx.blockNumber, 'blockNumber')
|
|
})
|
|
})
|