diff --git a/package-lock.json b/package-lock.json index c6fbc69..70d56c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "Apache-2.0", "dependencies": { "@oceanprotocol/contracts": "^1.1.3", - "@oceanprotocol/lib": "^1.1.8", + "@oceanprotocol/lib": "^2.0.0", "cross-fetch": "^3.1.4" }, "devDependencies": { @@ -865,11 +865,11 @@ "integrity": "sha512-pn0rm4QKF8sVfDeJVlt18TV4Qj5oGgR/qQNO7O0GO2DQ3q8KHXRS15uRjmLTr5wW1kGcCHcTqEndXEEC7Elzkw==" }, "node_modules/@oceanprotocol/lib": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-1.1.8.tgz", - "integrity": "sha512-PT4Z7jhrOkNFnz7tROJCyQicA3pCj9HqKOtXEXHyttDvYIQxwhq5yrB8lC272463rptxWOI4yBTUYK4lVP3/Pg==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-2.0.0.tgz", + "integrity": "sha512-8MpMAkUG4LbalyN4UCcR+kZmo+Nmk/l22aTG3vQKjUfrF7mq3hvW5ThVlYll/sNarVTI/S086NvuxGX/ypcJuw==", "dependencies": { - "@oceanprotocol/contracts": "^1.0.0", + "@oceanprotocol/contracts": "^1.1.3", "bignumber.js": "^9.0.2", "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", @@ -15279,11 +15279,11 @@ "integrity": "sha512-pn0rm4QKF8sVfDeJVlt18TV4Qj5oGgR/qQNO7O0GO2DQ3q8KHXRS15uRjmLTr5wW1kGcCHcTqEndXEEC7Elzkw==" }, "@oceanprotocol/lib": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-1.1.8.tgz", - "integrity": "sha512-PT4Z7jhrOkNFnz7tROJCyQicA3pCj9HqKOtXEXHyttDvYIQxwhq5yrB8lC272463rptxWOI4yBTUYK4lVP3/Pg==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-2.0.0.tgz", + "integrity": "sha512-8MpMAkUG4LbalyN4UCcR+kZmo+Nmk/l22aTG3vQKjUfrF7mq3hvW5ThVlYll/sNarVTI/S086NvuxGX/ypcJuw==", "requires": { - "@oceanprotocol/contracts": "^1.0.0", + "@oceanprotocol/contracts": "^1.1.3", "bignumber.js": "^9.0.2", "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", diff --git a/package.json b/package.json index 6236098..1d4d6c4 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "test-dispenser": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/Dispenser.test.ts'", "test-fixed": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/FixedRateExchange.test.ts'", "test-users": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/users.test.ts'", + "test-ve": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/VeOcean.test.ts'", "lint": "eslint --ignore-path .gitignore --ext .js --ext .ts --ext .tsx .", "lint:fix": "eslint --ignore-path .gitignore --ext .js,.ts,.tsx . --fix", "format": "prettier --ignore-path .gitignore './**/*.{css,yml,js,ts,tsx,json,yaml}' --write", @@ -65,7 +66,7 @@ }, "dependencies": { "@oceanprotocol/contracts": "^1.1.3", - "@oceanprotocol/lib": "^1.1.8", + "@oceanprotocol/lib": "^2.0.0", "cross-fetch": "^3.1.4" }, "repository": { diff --git a/schema.graphql b/schema.graphql index 8568e13..005e4ba 100644 --- a/schema.graphql +++ b/schema.graphql @@ -461,4 +461,6 @@ type VeDeposit @entity { unlockTime: BigInt! type:BigInt! timestamp: BigInt! + block: Int! + tx: String! } \ No newline at end of file diff --git a/src/mappings/utils/veUtils.ts b/src/mappings/utils/veUtils.ts index 554fc64..02f2733 100644 --- a/src/mappings/utils/veUtils.ts +++ b/src/mappings/utils/veUtils.ts @@ -141,6 +141,8 @@ export function getDeposit(id: string): VeDeposit { deposit.unlockTime = BigInt.zero() deposit.type = BigInt.zero() deposit.timestamp = BigInt.zero() + deposit.tx = '' + deposit.block = 0 deposit.save() } return deposit diff --git a/src/mappings/veOCEAN.ts b/src/mappings/veOCEAN.ts index 7e865c0..2befd1d 100644 --- a/src/mappings/veOCEAN.ts +++ b/src/mappings/veOCEAN.ts @@ -16,6 +16,8 @@ export function handleDeposit(event: Deposit): void { deposit.unlockTime = locktime deposit.type = type deposit.timestamp = ts + deposit.block = event.block.number.toI32() + deposit.tx = event.transaction.hash.toHex() deposit.save() // -------------------------------------------- diff --git a/test/integration/Datatoken.test.ts b/test/integration/Datatoken.test.ts index 2451627..f9aff1b 100644 --- a/test/integration/Datatoken.test.ts +++ b/test/integration/Datatoken.test.ts @@ -1,5 +1,5 @@ import { - Erc20CreateParams, + DatatokenCreateParams, ProviderInstance, Nft, NftFactory, @@ -117,7 +117,7 @@ describe('Datatoken tests', async () => { transferable: true, owner: publisher } - const erc20Params: Erc20CreateParams = { + const erc20Params: DatatokenCreateParams = { templateIndex, cap, feeAmount: publishMarketFeeAmount, @@ -126,7 +126,7 @@ describe('Datatoken tests', async () => { minter: publisher, mpFeeAddress: marketPlaceFeeAddress } - const result = await Factory.createNftWithErc20( + const result = await Factory.createNftWithDatatoken( publisher, nftParams, erc20Params @@ -343,7 +343,7 @@ describe('Datatoken tests', async () => { transferable: true, owner: publisher } - const erc20Params: Erc20CreateParams = { + const erc20Params: DatatokenCreateParams = { templateIndex, cap: '100000', feeAmount: '0', @@ -352,7 +352,7 @@ describe('Datatoken tests', async () => { minter: publisher, mpFeeAddress: ZERO_ADDRESS } - const result = await Factory.createNftWithErc20( + const result = await Factory.createNftWithDatatoken( publisher, nftParams, erc20Params diff --git a/test/integration/Dispenser.test.ts b/test/integration/Dispenser.test.ts index a93decd..a210018 100644 --- a/test/integration/Dispenser.test.ts +++ b/test/integration/Dispenser.test.ts @@ -1,5 +1,5 @@ import { - Erc20CreateParams, + DatatokenCreateParams, NftFactory, NftCreateData, sleep, @@ -70,15 +70,16 @@ describe('Dispenser tests', async () => { it('should initialize Dispenser and datatoken class', async () => { dispenser = new Dispenser( + addresses.Dispenser, web3, 8996, - addresses.Dispenser, + null, DispenserTemplate.abi as AbiItem[] ) - assert(dispenser.dispenserAbi !== null) + assert(dispenser.getDefaultAbi() !== null) - datatoken = new Datatoken(web3, 8996, ERC20Template.abi as AbiItem[]) - assert(datatoken.datatokensAbi !== null) + datatoken = new Datatoken(web3, 8996, null, ERC20Template.abi as AbiItem[]) + assert(datatoken.getDefaultAbi() !== null) }) it('Deploying an NFT with ERC20', async () => { @@ -94,7 +95,7 @@ describe('Dispenser tests', async () => { transferable: true, owner: publisher } - const erc20Params: Erc20CreateParams = { + const erc20Params: DatatokenCreateParams = { templateIndex, cap, feeAmount, @@ -104,7 +105,7 @@ describe('Dispenser tests', async () => { mpFeeAddress: marketPlaceFeeAddress } - const tx = await Factory.createNftWithErc20( + const tx = await Factory.createNftWithDatatoken( publisher, nftParams, erc20Params @@ -263,7 +264,7 @@ describe('Dispenser tests', async () => { it('Make user1 minter', async () => { await datatoken.addMinter(dtAddress, publisher, user1) - assert((await datatoken.getDTPermissions(dtAddress, user1)).minter === true) + assert((await datatoken.getPermissions(dtAddress, user1)).minter === true) await sleep(sleepMs) const minterQuery = { query: `query {token(id: "${dtAddress}"){minter{id}}}` diff --git a/test/integration/FixedRateExchange.test.ts b/test/integration/FixedRateExchange.test.ts index f6a8811..b1e81cf 100644 --- a/test/integration/FixedRateExchange.test.ts +++ b/test/integration/FixedRateExchange.test.ts @@ -1,5 +1,5 @@ import { - Erc20CreateParams, + DatatokenCreateParams, NftFactory, NftCreateData, sleep, @@ -89,7 +89,7 @@ describe('Fixed Rate Exchange tests', async () => { transferable: true, owner: publisher } - const erc20Params: Erc20CreateParams = { + const erc20Params: DatatokenCreateParams = { templateIndex, cap, feeAmount, @@ -111,7 +111,7 @@ describe('Fixed Rate Exchange tests', async () => { withMint: false } - const result = await Factory.createNftErc20WithFixedRate( + const result = await Factory.createNftWithDatatokenWithFixedRate( publisher, nftParams, erc20Params, @@ -392,7 +392,7 @@ describe('Fixed Rate Exchange tests', async () => { }) it('Updates Fixed Rate Price', async () => { - fixedRate = new FixedRateExchange(web3, fixedRateAddress, 8996) + fixedRate = new FixedRateExchange(fixedRateAddress, web3, 8996) const priceQuery = { query: `query {fixedRateExchange(id: "${fixedRateId}"){ price @@ -627,8 +627,9 @@ describe('Fixed Rate Exchange tests', async () => { let user1Balance = await datatoken.balance(datatokenAddress, user1) assert(user1Balance === '0', 'incorrect value for: user1Balance') - const tx = (await fixedRate.buyDT(user1, exchangeId, dtAmount, '100')) - .events?.Swapped + const tx = ( + await fixedRate.buyDatatokens(user1, exchangeId, dtAmount, '100') + ).events?.Swapped await sleep(sleepMs) user1Balance = await datatoken.balance(datatokenAddress, user1) // user1 has 1 datatoken @@ -656,8 +657,8 @@ describe('Fixed Rate Exchange tests', async () => { }) it('User1 sells a datatoken', async () => { await datatoken.approve(datatokenAddress, fixedRateAddress, dtAmount, user1) - const tx = (await fixedRate.sellDT(user1, exchangeId, '10', '9')).events - ?.Swapped + const tx = (await fixedRate.sellDatatokens(user1, exchangeId, '10', '9')) + .events?.Swapped assert(tx != null) await sleep(sleepMs) const swapsQuery = { diff --git a/test/integration/Nft.test.ts b/test/integration/Nft.test.ts index 9d51204..d7da81c 100644 --- a/test/integration/Nft.test.ts +++ b/test/integration/Nft.test.ts @@ -1,5 +1,5 @@ import { - Erc20CreateParams, + DatatokenCreateParams, ProviderInstance, Nft, NftFactory, @@ -103,7 +103,7 @@ describe('NFT tests', async () => { transferable: true, owner: publisher } - const erc20Params: Erc20CreateParams = { + const erc20Params: DatatokenCreateParams = { templateIndex: 1, cap: '100000', feeAmount: '0', @@ -112,7 +112,7 @@ describe('NFT tests', async () => { minter: publisher, mpFeeAddress: '0x0000000000000000000000000000000000000000' } - const result = await Factory.createNftWithErc20( + const result = await Factory.createNftWithDatatoken( publisher, nftParams, erc20Params diff --git a/test/integration/SimplePublishConsume.test.ts b/test/integration/SimplePublishConsume.test.ts index 8568bd7..1f86e2b 100644 --- a/test/integration/SimplePublishConsume.test.ts +++ b/test/integration/SimplePublishConsume.test.ts @@ -1,6 +1,6 @@ import { Datatoken, - Erc20CreateParams, + DatatokenCreateParams, ProviderInstance, ProviderFees, Nft, @@ -105,7 +105,7 @@ describe('Simple Publish & consume test', async () => { transferable: true, owner: publisherAccount } - const erc20Params: Erc20CreateParams = { + const erc20Params: DatatokenCreateParams = { templateIndex: 1, cap: '100000', feeAmount: '0', @@ -114,7 +114,7 @@ describe('Simple Publish & consume test', async () => { minter: publisherAccount, mpFeeAddress: '0x0000000000000000000000000000000000000000' } - const result = await Factory.createNftWithErc20( + const result = await Factory.createNftWithDatatoken( publisherAccount, nftParams, erc20Params @@ -170,7 +170,7 @@ describe('Simple Publish & consume test', async () => { transferable: true, owner: publisherAccount } - const erc20Params: Erc20CreateParams = { + const erc20Params: DatatokenCreateParams = { templateIndex: 1, cap: '100000', feeAmount: '0', @@ -179,7 +179,7 @@ describe('Simple Publish & consume test', async () => { minter: publisherAccount, mpFeeAddress: '0x0000000000000000000000000000000000000000' } - const result = await Factory.createNftWithErc20( + const result = await Factory.createNftWithDatatoken( publisherAccount, nftParams, erc20Params diff --git a/test/integration/SimpleSubgraph.test.ts b/test/integration/SimpleSubgraph.test.ts index d7d88aa..38a5c00 100644 --- a/test/integration/SimpleSubgraph.test.ts +++ b/test/integration/SimpleSubgraph.test.ts @@ -1,5 +1,5 @@ import { - Erc20CreateParams, + DatatokenCreateParams, Nft, NftFactory, NftCreateData, @@ -49,7 +49,7 @@ describe('Tests coverage without provider/aquarius', async () => { transferable: true, owner: publisherAccount } - const erc20Params: Erc20CreateParams = { + const erc20Params: DatatokenCreateParams = { templateIndex: 1, cap: '100000', feeAmount: '0', @@ -58,7 +58,7 @@ describe('Tests coverage without provider/aquarius', async () => { minter: publisherAccount, mpFeeAddress: '0x0000000000000000000000000000000000000000' } - const result = await Factory.createNftWithErc20( + const result = await Factory.createNftWithDatatoken( publisherAccount, nftParams, erc20Params @@ -89,7 +89,7 @@ describe('Tests coverage without provider/aquarius', async () => { transferable: true, owner: publisherAccount } - const erc20Params: Erc20CreateParams = { + const erc20Params: DatatokenCreateParams = { templateIndex: 1, cap: '100000', feeAmount: '0', @@ -98,7 +98,7 @@ describe('Tests coverage without provider/aquarius', async () => { minter: publisherAccount, mpFeeAddress: '0x0000000000000000000000000000000000000000' } - const result = await Factory.createNftWithErc20( + const result = await Factory.createNftWithDatatoken( publisherAccount, nftParams, erc20Params diff --git a/test/integration/VeOcean.test.ts b/test/integration/VeOcean.test.ts new file mode 100644 index 0000000..75ce699 --- /dev/null +++ b/test/integration/VeOcean.test.ts @@ -0,0 +1,362 @@ +import { + VeOcean, + VeAllocate, + NftFactory, + calculateEstimatedGas, + sendTx, + approve, + ConfigHelper, + 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' + +describe('veOcean tests', async () => { + let nftFactory + let veOcean: VeOcean + let veAllocate: VeAllocate + let ownerAccount: string + let Alice: string + let Bob: string + 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 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[] + const tokenContract = new web3.eth.Contract(minAbi, addresses.Ocean) + const estGas = await calculateEstimatedGas( + ownerAccount, + tokenContract.methods.mint, + Alice, + web3.utils.toWei('1000') + ) + await sendTx( + ownerAccount, + estGas, + web3, + 1, + tokenContract.methods.mint, + Alice, + web3.utils.toWei('1000') + ) + await sendTx( + ownerAccount, + estGas, + web3, + 1, + tokenContract.methods.mint, + Bob, + web3.utils.toWei('1000') + ) + veOcean = new VeOcean(addresses.veOCEAN, web3) + veAllocate = new VeAllocate(addresses.veAllocate, web3) + nftFactory = new NftFactory(addresses.ERC721Factory, web3) + }) + + it('Alice should lock 100 Ocean', async () => { + // since we can only lock once, we test if tx fails or not + // so if there is already a lock, skip it + let currentBalance = await veOcean.getLockedAmount(Alice) + let currentLock = await veOcean.lockEnd(Alice) + const amount = '100' + await approve( + web3, + config, + Alice, + addresses.Ocean, + addresses.veOCEAN, + amount + ) + const timestamp = Math.floor(Date.now() / 1000) + const unlockTime = timestamp + 7 * 86400 + + if (parseInt(currentBalance) > 0 || currentLock > 0) { + // we already have some locked tokens, so our transaction should fail + try { + await veOcean.lockTokens(Alice, amount, unlockTime) + assert(false, 'This should fail!') + } catch (e) { + // do nothing + } + } else { + await veOcean.lockTokens(Alice, amount, unlockTime) + } + currentBalance = await veOcean.getLockedAmount(Alice) + currentLock = await veOcean.lockEnd(Alice) + await sleep(2000) + const initialQuery = { + query: `query { + veOCEANs(id:"${Alice.toLowerCase()}"){ + id, + lockedAmount, + unlockTime + } + }` + } + const initialResponse = await fetch(subgraphUrl, { + method: 'POST', + body: JSON.stringify(initialQuery) + }) + const info = (await initialResponse.json()).data.veOCEANs + assert(info[0].id === Alice.toLowerCase()) + assert(info[0].lockedAmount === currentBalance) + assert(info[0].unlockTime === currentLock) + }) + + it('Alice should increase the lock time', async () => { + const currentLock = await veOcean.lockEnd(Alice) + const newLock = parseInt(String(currentLock)) + 7 * 86400 + await veOcean.increaseUnlockTime(Alice, newLock) + const newCurrentLock = await veOcean.lockEnd(Alice) + await sleep(2000) + const initialQuery = { + query: `query { + veOCEANs(id:"${Alice.toLowerCase()}"){ + id, + lockedAmount, + unlockTime + } + }` + } + const initialResponse = await fetch(subgraphUrl, { + method: 'POST', + body: JSON.stringify(initialQuery) + }) + const info = (await initialResponse.json()).data.veOCEANs + assert( + info[0].unlockTime === newCurrentLock, + 'Expected lock ' + + newCurrentLock + + ' to equal subgraph value ' + + info[0].unlockTime + ) + }) + + it('Alice should increase the locked amount', async () => { + const amount = '200' + await approve( + web3, + config, + Alice, + addresses.Ocean, + addresses.veOCEAN, + amount + ) + await veOcean.increaseAmount(Alice, amount) + const newCurrentBalance = await veOcean.getLockedAmount(Alice) + const newCurrentLock = await veOcean.lockEnd(Alice) + await sleep(2000) + const initialQuery = { + query: `query { + veOCEANs(id:"${Alice.toLowerCase()}"){ + id, + lockedAmount, + unlockTime + } + }` + } + const initialResponse = await fetch(subgraphUrl, { + method: 'POST', + body: JSON.stringify(initialQuery) + }) + const info = (await initialResponse.json()).data.veOCEANs + assert( + info[0].unlockTime === newCurrentLock, + 'Expected lock ' + + newCurrentLock + + ' to equal subgraph value ' + + info[0].unlockTime + ) + assert( + info[0].lockedAmount === newCurrentBalance, + 'Expected balance ' + + newCurrentBalance + + ' to equal subgraph value ' + + info[0].lockedAmount + ) + }) + + it('Alice should publish 3 NFTs', async () => { + // publish 3 nfts + nft1 = await nftFactory.createNFT(Alice, { + name: 'testNft1', + symbol: 'TSTF1', + templateIndex: 1, + tokenURI: '', + transferable: true, + owner: Alice + }) + nft2 = await nftFactory.createNFT(Alice, { + name: 'testNft2', + symbol: 'TSTF2', + templateIndex: 1, + tokenURI: '', + transferable: true, + owner: Alice + }) + nft3 = await nftFactory.createNFT(Alice, { + name: 'testNft3', + symbol: 'TSTF3', + templateIndex: 1, + tokenURI: '', + transferable: true, + owner: Alice + }) + }) + + it('Alice should allocate 10% to NFT1', async () => { + await veAllocate.setAllocation(Alice, '1000', nft1, chainId) + const newTotalAllocation = await veAllocate.getTotalAllocation(Alice) + await sleep(2000) + let initialQuery = { + query: `query { + veAllocateUsers(id:"${Alice.toLowerCase()}"){ + id, + allocatedTotal + } + }` + } + let initialResponse = await fetch(subgraphUrl, { + method: 'POST', + body: JSON.stringify(initialQuery) + }) + let info = (await initialResponse.json()).data.veAllocateUsers + assert( + info[0].allocatedTotal === newTotalAllocation, + 'Expected totalAllocation ' + + newTotalAllocation + + ' to equal subgraph value ' + + info[0].allocatedTotal + ) + initialQuery = { + query: `query { + veAllocations( + where: {allocationUser:"${Alice.toLowerCase()}", chainId:"${chainId}", nftAddress:"${nft1.toLowerCase()}"} + ){ + id, + allocated + } + }` + } + initialResponse = await fetch(subgraphUrl, { + method: 'POST', + body: JSON.stringify(initialQuery) + }) + info = (await initialResponse.json()).data.veAllocations + assert( + info[0].allocated === '1000', + 'Expected totalAllocation 1000 to equal subgraph value ' + + info[0].allocatedTotal + ) + }) + + it('Alice should allocate 10% to NFT2 and 20% to NFT3', async () => { + await veAllocate.setBatchAllocation( + Alice, + ['1000', '2000'], + [nft2, nft3], + [chainId, chainId] + ) + const totalAllocation = await veAllocate.getTotalAllocation(Alice) + + await sleep(2000) + let initialQuery = { + query: `query { + veAllocateUsers(id:"${Alice.toLowerCase()}"){ + id, + allocatedTotal + } + }` + } + let initialResponse = await fetch(subgraphUrl, { + method: 'POST', + body: JSON.stringify(initialQuery) + }) + let info = (await initialResponse.json()).data.veAllocateUsers + assert( + info[0].allocatedTotal === totalAllocation, + 'Expected totalAllocation ' + + totalAllocation + + ' to equal subgraph value ' + + info[0].allocatedTotal + ) + initialQuery = { + query: `query { + veAllocations( + where: {allocationUser:"${Alice.toLowerCase()}", chainId:"${chainId}", nftAddress:"${nft2.toLowerCase()}"} + ){ + id, + allocated + } + }` + } + initialResponse = await fetch(subgraphUrl, { + method: 'POST', + body: JSON.stringify(initialQuery) + }) + info = (await initialResponse.json()).data.veAllocations + assert( + info[0].allocated === '1000', + 'Expected totalAllocation 1000 to equal subgraph value ' + + info[0].allocatedTotal + ) + initialQuery = { + query: `query { + veAllocations( + where: {allocationUser:"${Alice.toLowerCase()}", chainId:"${chainId}", nftAddress:"${nft3.toLowerCase()}"} + ){ + id, + allocated + } + }` + } + initialResponse = await fetch(subgraphUrl, { + method: 'POST', + body: JSON.stringify(initialQuery) + }) + info = (await initialResponse.json()).data.veAllocations + assert( + info[0].allocated === '2000', + 'Expected totalAllocation 1000 to equal subgraph value ' + + info[0].allocatedTotal + ) + }) +}) diff --git a/test/integration/users.test.ts b/test/integration/users.test.ts index 33cf747..29a4de6 100644 --- a/test/integration/users.test.ts +++ b/test/integration/users.test.ts @@ -1,5 +1,5 @@ import { - Erc20CreateParams, + DatatokenCreateParams, NftFactory, NftCreateData, sleep, @@ -104,7 +104,7 @@ describe('User tests', async () => { transferable: true, owner: publisher } - const erc20Params: Erc20CreateParams = { + const erc20Params: DatatokenCreateParams = { templateIndex, cap, feeAmount, @@ -126,7 +126,7 @@ describe('User tests', async () => { withMint: false } - const result = await Factory.createNftErc20WithFixedRate( + const result = await Factory.createNftWithDatatokenWithFixedRate( publisher, nftParams, erc20Params, @@ -177,8 +177,8 @@ describe('User tests', async () => { let user1Balance = await datatoken.balance(datatokenAddress, user1) assert(user1Balance === '0', 'incorrect value for: user1Balance') - fixedRate = new FixedRateExchange(web3, fixedRateAddress, 8996) - await fixedRate.buyDT(user1, exchangeId, dtAmount, '100') + fixedRate = new FixedRateExchange(fixedRateAddress, web3, 8996) + await fixedRate.buyDatatokens(user1, exchangeId, dtAmount, '100') await sleep(sleepMs) user1Balance = await datatoken.balance(datatokenAddress, user1) @@ -199,8 +199,8 @@ describe('User tests', async () => { it('User1 sells a datatoken', async () => { const initialUser = await userQuery(user1) await datatoken.approve(datatokenAddress, fixedRateAddress, dtAmount, user1) - const tx = (await fixedRate.sellDT(user1, exchangeId, '10', '9')).events - ?.Swapped + const tx = (await fixedRate.sellDatatokens(user1, exchangeId, '10', '9')) + .events?.Swapped assert(tx != null) const user = await userQuery(user1) @@ -227,7 +227,7 @@ describe('User tests', async () => { transferable: true, owner: publisher } - const erc20Params: Erc20CreateParams = { + const erc20Params: DatatokenCreateParams = { templateIndex, cap: '100000', feeAmount: '0', @@ -236,7 +236,7 @@ describe('User tests', async () => { minter: publisher, mpFeeAddress: feeAddress } - const result = await Factory.createNftWithErc20( + const result = await Factory.createNftWithDatatoken( publisher, nftParams, erc20Params