From a40997f0067b58fec22111687b0eb174d4ae4d81 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Mon, 21 Nov 2022 13:02:29 +0300 Subject: [PATCH] Updating nftOwner in Order --- package.json | 1 + src/mappings/erc20Templates.ts | 6 ++++++ test/integration/Datatoken.test.ts | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b471c54..f204dd3 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "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'", "test-df": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/DFRewards.test.ts'", + "test-dt": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/Datatoken.test.ts'", "test-zend": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/ZEnding.test.ts'", "lint": "eslint --ignore-path .gitignore --ext .js --ext .ts --ext .tsx .", "lint:fix": "eslint --ignore-path .gitignore --ext .js,.ts,.tsx . --fix", diff --git a/src/mappings/erc20Templates.ts b/src/mappings/erc20Templates.ts index e48040f..4c2056d 100644 --- a/src/mappings/erc20Templates.ts +++ b/src/mappings/erc20Templates.ts @@ -38,6 +38,12 @@ export function handleOrderStarted(event: OrderStarted): void { const consumer = getUser(event.params.consumer.toHex()) order.consumer = consumer.id + if (token.nft) { + const nft = Nft.load(token.nft as string) as Nft + const nftOwner = getUser(nft.owner) + order.nftOwner = nftOwner.id + } + const payer = getUser(event.params.payer.toHex()) payer.totalOrders = payer.totalOrders.plus(integer.ONE) payer.save() diff --git a/test/integration/Datatoken.test.ts b/test/integration/Datatoken.test.ts index f9aff1b..5256e6e 100644 --- a/test/integration/Datatoken.test.ts +++ b/test/integration/Datatoken.test.ts @@ -368,7 +368,7 @@ describe('Datatoken tests', async () => { assert(Number(user2balance) === 0, 'Invalid user2 balance') const query = { - query: `query {token(id: "${newDtAddress.toLowerCase()}"){id,orderCount,orders {id}}}` + query: `query {token(id: "${newDtAddress.toLowerCase()}"){id,orderCount,orders {id, nftOwner{id}}}}` } await sleep(2000) @@ -428,5 +428,6 @@ describe('Datatoken tests', async () => { assert(token, 'Invalid token') assert(token.orderCount === '1', 'Invalid orderCount after order') assert(token.orders[0].id === orderId) + assert(token.orders[0].nftOwner.id === publisher, 'invalid nftOwner') }) })