From 40a008394192df13b71de4826305a015ce037ba4 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Wed, 27 Mar 2024 10:20:32 +0200 Subject: [PATCH] update: add tests for fungible token Signed-off-by: svetoslav-nikol0v --- .../integration/TokenUpdateIntegrationTest.js | 256 +++++++++++++++++- 1 file changed, 250 insertions(+), 6 deletions(-) diff --git a/test/integration/TokenUpdateIntegrationTest.js b/test/integration/TokenUpdateIntegrationTest.js index 3fa65a41a..6795de8d7 100644 --- a/test/integration/TokenUpdateIntegrationTest.js +++ b/test/integration/TokenUpdateIntegrationTest.js @@ -460,7 +460,7 @@ describe("TokenUpdate", function () { } }); - it("should update token metadata", async function () { + it("should update the metadata of non-fungible token", async function () { this.timeout(120000); const operatorId = env.operatorId; @@ -508,7 +508,57 @@ describe("TokenUpdate", function () { expect(tokeInfo.metadata).to.eql(newMetadata); }); - it("should NOT update token metadata", async function () { + it("should update the metadata of fungible token", async function () { + this.timeout(120000); + + const operatorId = env.operatorId; + const operatorKey = env.operatorKey; + const metadataKey = PrivateKey.generateECDSA(); + const supplyKey = PrivateKey.generateECDSA(); + const metadata = new Uint8Array([1]); + const newMetadata = new Uint8Array([1, 2]); + let tokeInfo; + + const tokenCreateTx = new TokenCreateTransaction() + .setTokenName("Test") + .setTokenSymbol("T") + .setSupplyKey(supplyKey) + .setTokenType(TokenType.FungibleCommon) + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(operatorId) + .setAdminKey(operatorKey) + .setMetadata(metadata) + .setMetadataKey(metadataKey); + + const tokenCreateTxresponse = await tokenCreateTx.execute(env.client); + const tokenCreateTxReceipt = await tokenCreateTxresponse.getReceipt( + env.client, + ); + const tokenId = tokenCreateTxReceipt.tokenId; + + tokeInfo = await new TokenInfoQuery() + .setTokenId(tokenId) + .execute(env.client); + expect(tokeInfo.metadata).to.eql(metadata); + + const tokenUpdateTx = new TokenUpdateTransaction() + .setTokenId(tokenId) + .setMetadata(newMetadata) + .freezeWith(env.client); + + await ( + await (await tokenUpdateTx.sign(metadataKey)).execute(env.client) + ).getReceipt(env.client); + + tokeInfo = await new TokenInfoQuery() + .setTokenId(tokenId) + .execute(env.client); + + expect(tokeInfo.metadata).to.eql(newMetadata); + }); + + it("should NOT update the metadata of non-fungible token", async function () { this.timeout(120000); const operatorId = env.operatorId; @@ -554,7 +604,55 @@ describe("TokenUpdate", function () { expect(tokeInfo.metadata).to.eql(metadata); }); - it("should earse token metadata", async function () { + it("should NOT update the metadata of fungible token", async function () { + this.timeout(120000); + + const operatorId = env.operatorId; + const operatorKey = env.operatorKey; + const metadataKey = PrivateKey.generateECDSA(); + const supplyKey = PrivateKey.generateECDSA(); + const metadata = new Uint8Array([1]); + let tokeInfo; + + const tokenCreateTx = new TokenCreateTransaction() + .setTokenName("Test") + .setTokenSymbol("T") + .setSupplyKey(supplyKey) + .setTokenType(TokenType.FungibleCommon) + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(operatorId) + .setAdminKey(operatorKey) + .setMetadata(metadata) + .setMetadataKey(metadataKey); + + const tokenCreateTxresponse = await tokenCreateTx.execute(env.client); + const tokenCreateTxReceipt = await tokenCreateTxresponse.getReceipt( + env.client, + ); + const tokenId = tokenCreateTxReceipt.tokenId; + + tokeInfo = await new TokenInfoQuery() + .setTokenId(tokenId) + .execute(env.client); + expect(tokeInfo.metadata).to.eql(metadata); + + const tokenUpdateTx = new TokenUpdateTransaction() + .setTokenId(tokenId) + .freezeWith(env.client); + + await ( + await (await tokenUpdateTx.sign(metadataKey)).execute(env.client) + ).getReceipt(env.client); + + tokeInfo = await new TokenInfoQuery() + .setTokenId(tokenId) + .execute(env.client); + + expect(tokeInfo.metadata).to.eql(metadata); + }); + + it("should earse the metadata of non-fungible token", async function () { this.timeout(120000); const operatorId = env.operatorId; @@ -602,8 +700,58 @@ describe("TokenUpdate", function () { expect(tokeInfo.metadata).to.eql(newMetadata); }); + it("should earse the metadata of fungible token", async function () { + this.timeout(120000); + + const operatorId = env.operatorId; + const operatorKey = env.operatorKey; + const metadataKey = PrivateKey.generateECDSA(); + const supplyKey = PrivateKey.generateECDSA(); + const metadata = new Uint8Array([1]); + const newMetadata = new Uint8Array(); + let tokeInfo; + + const tokenCreateTx = new TokenCreateTransaction() + .setTokenName("Test") + .setTokenSymbol("T") + .setSupplyKey(supplyKey) + .setTokenType(TokenType.FungibleCommon) + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(operatorId) + .setAdminKey(operatorKey) + .setMetadata(metadata) + .setMetadataKey(metadataKey); + + const tokenCreateTxresponse = await tokenCreateTx.execute(env.client); + const tokenCreateTxReceipt = await tokenCreateTxresponse.getReceipt( + env.client, + ); + const tokenId = tokenCreateTxReceipt.tokenId; + + tokeInfo = await new TokenInfoQuery() + .setTokenId(tokenId) + .execute(env.client); + expect(tokeInfo.metadata).to.eql(metadata); + + const tokenUpdateTx = new TokenUpdateTransaction() + .setTokenId(tokenId) + .setMetadata(newMetadata) + .freezeWith(env.client); + + await ( + await (await tokenUpdateTx.sign(metadataKey)).execute(env.client) + ).getReceipt(env.client); + + tokeInfo = await new TokenInfoQuery() + .setTokenId(tokenId) + .execute(env.client); + + expect(tokeInfo.metadata).to.eql(newMetadata); + }); + /** @summary Currently the transaction passing even when the transaction is signed with wrong metadata key */ - it("should NOT update token metadata if the transaction is not signed with metadata key", async function () { + it("should NOT update the metadata of non-fungible token if the transaction is not signed with metadata key", async function () { this.timeout(120000); const operatorId = env.operatorId; @@ -648,8 +796,56 @@ describe("TokenUpdate", function () { } }); + /** @summary Currently the transaction passing even when the transaction is signed with wrong metadata key */ + it("should NOT update the metadata of fungible token if the transaction is not signed with metadata key", async function () { + this.timeout(120000); + + const operatorId = env.operatorId; + const operatorKey = env.operatorKey; + const metadataKey = PrivateKey.generateECDSA(); + const wrongMetadataKey = PrivateKey.generateECDSA(); + const supplyKey = PrivateKey.generateECDSA(); + const metadata = new Uint8Array([1]); + const newMetadata = new Uint8Array([1, 2]); + + try { + const tokenCreateTx = new TokenCreateTransaction() + .setTokenName("Test") + .setTokenSymbol("T") + .setSupplyKey(supplyKey) + .setTokenType(TokenType.FungibleCommon) + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(operatorId) + .setAdminKey(operatorKey) + .setMetadata(metadata) + .setMetadataKey(metadataKey); + + const tokenCreateTxresponse = await tokenCreateTx.execute( + env.client, + ); + const tokenCreateTxReceipt = await tokenCreateTxresponse.getReceipt( + env.client, + ); + const tokenId = tokenCreateTxReceipt.tokenId; + + const tokenUpdateTx = new TokenUpdateTransaction() + .setTokenId(tokenId) + .setMetadata(newMetadata) + .freezeWith(env.client); + + await ( + await ( + await tokenUpdateTx.sign(wrongMetadataKey) + ).execute(env.client) + ).getReceipt(env.client); + } catch (error) { + expect(error.status).to.be.eql(Status.InvalidSignature); + } + }); + /** @summary Currently the transaction passing even when the metadata key is NOT set */ - it("should NOT update token metadata if the metadata key is NOT set", async function () { + it("should NOT update the metadata of non-fungible token if the metadata key is NOT set", async function () { this.timeout(120000); const operatorId = env.operatorId; @@ -667,7 +863,55 @@ describe("TokenUpdate", function () { .setTokenType(TokenType.NonFungibleUnique) .setTreasuryAccountId(operatorId) .setAdminKey(operatorKey) - .setMetadata(metadata); + .setMetadata(metadata) + .setMetadataKey(metadataKey); + + const tokenCreateTxresponse = await tokenCreateTx.execute( + env.client, + ); + const tokenCreateTxReceipt = await tokenCreateTxresponse.getReceipt( + env.client, + ); + const tokenId = tokenCreateTxReceipt.tokenId; + + const tokenUpdateTx = new TokenUpdateTransaction() + .setTokenId(tokenId) + .setMetadata(newMetadata) + .freezeWith(env.client); + + await ( + await ( + await tokenUpdateTx.sign(metadataKey) + ).execute(env.client) + ).getReceipt(env.client); + } catch (error) { + expect(error.status).to.be.eql(Status.InvalidSignature); + } + }); + + /** @summary Currently the transaction passing even when the metadata key is NOT set */ + it("should NOT update the metadata of fungible token if the metadata key is NOT set", async function () { + this.timeout(120000); + + const operatorId = env.operatorId; + const operatorKey = env.operatorKey; + const metadataKey = PrivateKey.generateECDSA(); + const supplyKey = PrivateKey.generateECDSA(); + const metadata = new Uint8Array([1]); + const newMetadata = new Uint8Array([1, 2]); + + try { + const tokenCreateTx = new TokenCreateTransaction() + .setTokenName("Test") + .setTokenSymbol("T") + .setSupplyKey(supplyKey) + .setTokenType(TokenType.FungibleCommon) + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(operatorId) + .setAdminKey(operatorKey) + .setMetadata(metadata) + .setMetadataKey(metadataKey); const tokenCreateTxresponse = await tokenCreateTx.execute( env.client,