mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
fix tokenRemoved (#549)
This commit is contained in:
parent
93a05eb767
commit
868f991f17
@ -86,7 +86,7 @@ export function handleTokenRemoved(event: TokenRemoved): void {
|
||||
while (existingTokens.length > 0) {
|
||||
const role = existingTokens.shift().toString()
|
||||
if (!role) break
|
||||
if (role !== event.params.token.toHexString()) newList.push(role)
|
||||
if (role != event.params.token.toHexString()) newList.push(role)
|
||||
}
|
||||
opc.approvedTokens = newList
|
||||
opc.save()
|
||||
@ -112,7 +112,7 @@ export function handleSSContractRemoved(event: SSContractRemoved): void {
|
||||
while (existingContracts.length > 0) {
|
||||
const role = existingContracts.shift().toString()
|
||||
if (!role) break
|
||||
if (role !== event.params.contractAddress.toHexString()) newList.push(role)
|
||||
if (role != event.params.contractAddress.toHexString()) newList.push(role)
|
||||
}
|
||||
templates.ssTemplates = newList
|
||||
templates.save()
|
||||
@ -144,7 +144,7 @@ export function handleFixedRateContractRemoved(
|
||||
while (existingContracts.length > 0) {
|
||||
const role = existingContracts.shift().toString()
|
||||
if (!role) break
|
||||
if (role !== event.params.contractAddress.toHexString()) newList.push(role)
|
||||
if (role != event.params.contractAddress.toHexString()) newList.push(role)
|
||||
}
|
||||
templates.fixedRateTemplates = newList
|
||||
templates.save()
|
||||
@ -175,7 +175,7 @@ export function handleDispenserContractRemoved(
|
||||
while (existingContracts.length > 0) {
|
||||
const role = existingContracts.shift().toString()
|
||||
if (!role) break
|
||||
if (role !== event.params.contractAddress.toHexString()) newList.push(role)
|
||||
if (role != event.params.contractAddress.toHexString()) newList.push(role)
|
||||
}
|
||||
templates.dispenserTemplates = newList
|
||||
templates.save()
|
||||
|
165
test/integration/FactoryRouter.test.ts
Normal file
165
test/integration/FactoryRouter.test.ts
Normal file
@ -0,0 +1,165 @@
|
||||
import {
|
||||
Router,
|
||||
NftFactory,
|
||||
calculateEstimatedGas,
|
||||
sendTx,
|
||||
sleep
|
||||
} from '@oceanprotocol/lib'
|
||||
import { AbiItem } from 'web3-utils'
|
||||
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'
|
||||
|
||||
const minAbi = [
|
||||
{
|
||||
constant: false,
|
||||
inputs: [
|
||||
{ name: 'to', type: 'address' },
|
||||
{ name: 'value', type: 'uint256' }
|
||||
],
|
||||
name: 'mint',
|
||||
outputs: [{ name: '', type: 'bool' }],
|
||||
payable: false,
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
}
|
||||
] as AbiItem[]
|
||||
|
||||
async function getSubgraphApprovedTokens() {
|
||||
const tokens: string[] = []
|
||||
const initialQuery = {
|
||||
query: `query{
|
||||
opcs{
|
||||
approvedTokens{
|
||||
id
|
||||
}
|
||||
}
|
||||
}`
|
||||
}
|
||||
const initialResponse = await fetch(subgraphUrl, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(initialQuery)
|
||||
})
|
||||
const info = (await initialResponse.json()).data.opcs[0].approvedTokens
|
||||
for (let i = 0; i < info.length; i++) tokens.push(info[i].id)
|
||||
return tokens
|
||||
}
|
||||
|
||||
describe('FactoryRouter tests', async () => {
|
||||
let factory
|
||||
let router: Router
|
||||
let ownerAccount: string
|
||||
let Alice: string
|
||||
let Bob: string
|
||||
let datatokenAddress
|
||||
// let nft1, nft2, nft3
|
||||
// let chainId
|
||||
// const configHelper = new ConfigHelper()
|
||||
// const config = configHelper.getConfig('development')
|
||||
|
||||
before(async () => {
|
||||
const accounts = await web3.eth.getAccounts()
|
||||
// chainId = await web3.eth.getChainId()
|
||||
ownerAccount = accounts[0]
|
||||
Alice = accounts[1]
|
||||
Bob = accounts[2]
|
||||
|
||||
const tokenContract = new web3.eth.Contract(minAbi, addresses.Ocean)
|
||||
const estGas = await calculateEstimatedGas(
|
||||
ownerAccount,
|
||||
tokenContract.methods.mint,
|
||||
Alice,
|
||||
web3.utils.toWei('100000')
|
||||
)
|
||||
await sendTx(
|
||||
ownerAccount,
|
||||
estGas,
|
||||
web3,
|
||||
1,
|
||||
tokenContract.methods.mint,
|
||||
Alice,
|
||||
web3.utils.toWei('100000')
|
||||
)
|
||||
await sendTx(
|
||||
ownerAccount,
|
||||
estGas,
|
||||
web3,
|
||||
1,
|
||||
tokenContract.methods.mint,
|
||||
Bob,
|
||||
web3.utils.toWei('100000')
|
||||
)
|
||||
router = new Router(addresses.Router, web3)
|
||||
// nftFactory = new NftFactory(addresses.ERC721Factory, web3)
|
||||
factory = new NftFactory(addresses.ERC721Factory, web3)
|
||||
})
|
||||
|
||||
it('Ocean token should be in the approve token list', async () => {
|
||||
// since we can only lock once, we test if tx fails or not
|
||||
// so if there is already a lock, skip it
|
||||
const tokens = await getSubgraphApprovedTokens()
|
||||
assert(tokens.includes(addresses.Ocean.toLowerCase()))
|
||||
assert(tokens.length === 1)
|
||||
})
|
||||
it('Owner should add another token in the approved list', async () => {
|
||||
const nftName = 'testNFT'
|
||||
const nftSymbol = 'TST'
|
||||
const marketPlaceFeeAddress = '0x1230000000000000000000000000000000000000'
|
||||
const feeToken = '0x3210000000000000000000000000000000000000'
|
||||
const publishMarketFeeAmount = '0.1'
|
||||
const cap = '10000'
|
||||
const templateIndex = 1
|
||||
const result = await factory.createNftWithDatatoken(
|
||||
Alice,
|
||||
{
|
||||
name: nftName,
|
||||
symbol: nftSymbol,
|
||||
templateIndex,
|
||||
tokenURI: '',
|
||||
transferable: true,
|
||||
owner: Alice
|
||||
},
|
||||
{
|
||||
templateIndex,
|
||||
cap,
|
||||
feeAmount: publishMarketFeeAmount,
|
||||
paymentCollector: '0x0000000000000000000000000000000000000000',
|
||||
feeToken,
|
||||
minter: Alice,
|
||||
mpFeeAddress: marketPlaceFeeAddress,
|
||||
name: 'DT1',
|
||||
symbol: 'DT1'
|
||||
}
|
||||
)
|
||||
datatokenAddress = result.events.TokenCreated.returnValues[0].toLowerCase()
|
||||
await router.addApprovedToken(ownerAccount, datatokenAddress)
|
||||
await sleep(2000)
|
||||
const tokens = await getSubgraphApprovedTokens()
|
||||
assert(tokens.includes(datatokenAddress.toLowerCase()))
|
||||
assert(tokens.length === 2)
|
||||
})
|
||||
|
||||
it('Owner should remove token from the approved list', async () => {
|
||||
await router.removeApprovedToken(ownerAccount, datatokenAddress)
|
||||
await sleep(2000)
|
||||
const tokens = await getSubgraphApprovedTokens()
|
||||
assert(!tokens.includes(datatokenAddress.toLowerCase()))
|
||||
assert(tokens.length === 1)
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user