From d2d78c12670f6a1719d8e37affadbe7dfdfd2f2f Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Wed, 5 Jun 2024 12:26:37 +0300 Subject: [PATCH] run pretty --- src/proto/serializer.spec.ts | 48 +++- src/proto/serializer.ts | 10 +- src/relayedTransactionV1Builder.spec.ts | 70 +++-- src/relayedTransactionV2Builder.spec.ts | 11 +- src/signableMessage.spec.ts | 22 +- src/smartcontracts/codec/binary.spec.ts | 244 ++++++++++++------ src/smartcontracts/typesystem/factory.spec.ts | 2 +- src/smartcontracts/typesystem/variadic.ts | 8 +- src/testutils/contractController.ts | 27 +- src/testutils/mockNetworkProvider.ts | 10 +- .../tokenOperationsFactory.spec.ts | 76 ++++-- .../tokenOperationsFactoryConfig.ts | 2 +- .../tokenOperationsOutcomeParser.spec.ts | 36 +-- src/transactionWatcher.spec.ts | 51 ++-- src/transferTransactionsFactory.spec.ts | 72 ++++-- 15 files changed, 464 insertions(+), 225 deletions(-) diff --git a/src/proto/serializer.spec.ts b/src/proto/serializer.spec.ts index f92acf0e..97a88b5c 100644 --- a/src/proto/serializer.spec.ts +++ b/src/proto/serializer.spec.ts @@ -23,14 +23,17 @@ describe("serialize transactions", () => { sender: wallets.alice.address, receiver: wallets.bob.address, gasLimit: 50000, - chainID: "local-testnet" + chainID: "local-testnet", }); const signer = wallets.alice.signer; transaction.applySignature(await signer.sign(transaction.serializeForSigning())); let buffer = serializer.serializeTransaction(transaction); - assert.equal(buffer.toString("hex"), "0859120200001a208049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f82a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1388094ebdc0340d08603520d6c6f63616c2d746573746e6574580262403f08a1dd64fbb627d10b048e0b45b1390f29bb0e457762a2ccb710b029f299022a67a4b8e45cf62f4314afec2e56b5574c71e38df96cc41fae757b7ee5062503"); + assert.equal( + buffer.toString("hex"), + "0859120200001a208049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f82a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1388094ebdc0340d08603520d6c6f63616c2d746573746e6574580262403f08a1dd64fbb627d10b048e0b45b1390f29bb0e457762a2ccb710b029f299022a67a4b8e45cf62f4314afec2e56b5574c71e38df96cc41fae757b7ee5062503", + ); }); it("with data, no value", async () => { @@ -41,14 +44,17 @@ describe("serialize transactions", () => { receiver: wallets.bob.address, gasLimit: 80000, data: new TransactionPayload("hello"), - chainID: "local-testnet" + chainID: "local-testnet", }); const signer = wallets.alice.signer; transaction.applySignature(await signer.sign(transaction.serializeForSigning())); let buffer = serializer.serializeTransaction(transaction); - assert.equal(buffer.toString("hex"), "085a120200001a208049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f82a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1388094ebdc034080f1044a0568656c6c6f520d6c6f63616c2d746573746e657458026240f9e8c1caf7f36b99e7e76ee1118bf71b55cde11a2356e2b3adf15f4ad711d2e1982469cbba7eb0afbf74e8a8f78e549b9410cd86eeaa88fcba62611ac9f6e30e"); + assert.equal( + buffer.toString("hex"), + "085a120200001a208049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f82a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1388094ebdc034080f1044a0568656c6c6f520d6c6f63616c2d746573746e657458026240f9e8c1caf7f36b99e7e76ee1118bf71b55cde11a2356e2b3adf15f4ad711d2e1982469cbba7eb0afbf74e8a8f78e549b9410cd86eeaa88fcba62611ac9f6e30e", + ); }); it("with data, with value", async () => { @@ -59,14 +65,17 @@ describe("serialize transactions", () => { receiver: wallets.bob.address, gasLimit: 100000, data: new TransactionPayload("for the book"), - chainID: "local-testnet" + chainID: "local-testnet", }); const signer = wallets.alice.signer; transaction.applySignature(await signer.sign(transaction.serializeForSigning())); let buffer = serializer.serializeTransaction(transaction); - assert.equal(buffer.toString("hex"), "085b1209008ac7230489e800001a208049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f82a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1388094ebdc0340a08d064a0c666f722074686520626f6f6b520d6c6f63616c2d746573746e657458026240b45f22e9f57a6df22670fcc3566723a0711a05ac2547456de59fd222a54940e4a1d99bd414897ccbf5c02a842ad86e638989b7f4d30edd26c99a8cd1eb092304"); + assert.equal( + buffer.toString("hex"), + "085b1209008ac7230489e800001a208049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f82a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1388094ebdc0340a08d064a0c666f722074686520626f6f6b520d6c6f63616c2d746573746e657458026240b45f22e9f57a6df22670fcc3566723a0711a05ac2547456de59fd222a54940e4a1d99bd414897ccbf5c02a842ad86e638989b7f4d30edd26c99a8cd1eb092304", + ); }); it("with data, with large value", async () => { @@ -77,14 +86,17 @@ describe("serialize transactions", () => { receiver: wallets.bob.address, gasLimit: 100000, data: new TransactionPayload("for the spaceship"), - chainID: "local-testnet" + chainID: "local-testnet", }); const signer = wallets.alice.signer; transaction.applySignature(await signer.sign(transaction.serializeForSigning())); let buffer = serializer.serializeTransaction(transaction); - assert.equal(buffer.toString("hex"), "085c120e00018ee90ff6181f3761632000001a208049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f82a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1388094ebdc0340a08d064a11666f722074686520737061636573686970520d6c6f63616c2d746573746e65745802624001f05aa8cb0614e12a94ab9dcbde5e78370a4e05d23ef25a1fb9d5fcf1cb3b1f33b919cd8dafb1704efb18fa233a8aa0d3344fb6ee9b613a7d7a403786ffbd0a"); + assert.equal( + buffer.toString("hex"), + "085c120e00018ee90ff6181f3761632000001a208049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f82a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1388094ebdc0340a08d064a11666f722074686520737061636573686970520d6c6f63616c2d746573746e65745802624001f05aa8cb0614e12a94ab9dcbde5e78370a4e05d23ef25a1fb9d5fcf1cb3b1f33b919cd8dafb1704efb18fa233a8aa0d3344fb6ee9b613a7d7a403786ffbd0a", + ); }); it("with nonce = 0", async () => { @@ -96,13 +108,20 @@ describe("serialize transactions", () => { gasLimit: 80000, data: new TransactionPayload("hello"), chainID: "local-testnet", - version: new TransactionVersion(1) + version: new TransactionVersion(1), }); - transaction.applySignature(new Signature("dfa3e9f2fdec60dcb353bac3b3435b4a2ff251e7e98eaf8620f46c731fc70c8ba5615fd4e208b05e75fe0f7dc44b7a99567e29f94fcd91efac7e67b182cd2a04")) + transaction.applySignature( + new Signature( + "dfa3e9f2fdec60dcb353bac3b3435b4a2ff251e7e98eaf8620f46c731fc70c8ba5615fd4e208b05e75fe0f7dc44b7a99567e29f94fcd91efac7e67b182cd2a04", + ), + ); let buffer = serializer.serializeTransaction(transaction); - assert.equal(buffer.toString("hex"), "120200001a208049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f82a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1388094ebdc034080f1044a0568656c6c6f520d6c6f63616c2d746573746e657458016240dfa3e9f2fdec60dcb353bac3b3435b4a2ff251e7e98eaf8620f46c731fc70c8ba5615fd4e208b05e75fe0f7dc44b7a99567e29f94fcd91efac7e67b182cd2a04"); + assert.equal( + buffer.toString("hex"), + "120200001a208049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f82a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1388094ebdc034080f1044a0568656c6c6f520d6c6f63616c2d746573746e657458016240dfa3e9f2fdec60dcb353bac3b3435b4a2ff251e7e98eaf8620f46c731fc70c8ba5615fd4e208b05e75fe0f7dc44b7a99567e29f94fcd91efac7e67b182cd2a04", + ); }); it("with usernames", async () => { @@ -114,13 +133,16 @@ describe("serialize transactions", () => { senderUsername: "carol", receiverUsername: "alice", gasLimit: 50000, - chainID: "T" + chainID: "T", }); const signer = wallets.carol.signer; transaction.applySignature(await signer.sign(transaction.serializeForSigning())); const buffer = serializer.serializeTransaction(transaction); - assert.equal(buffer.toString("hex"), "08cc011209000de0b6b3a76400001a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e12205616c6963652a20b2a11555ce521e4944e09ab17549d85b487dcd26c84b5017a39e31a3670889ba32056361726f6c388094ebdc0340d086035201545802624051e6cd78fb3ab4b53ff7ad6864df27cb4a56d70603332869d47a5cf6ea977c30e696103e41e8dddf2582996ad335229fdf4acb726564dbc1a0bc9e705b511f06"); + assert.equal( + buffer.toString("hex"), + "08cc011209000de0b6b3a76400001a200139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e12205616c6963652a20b2a11555ce521e4944e09ab17549d85b487dcd26c84b5017a39e31a3670889ba32056361726f6c388094ebdc0340d086035201545802624051e6cd78fb3ab4b53ff7ad6864df27cb4a56d70603332869d47a5cf6ea977c30e696103e41e8dddf2582996ad335229fdf4acb726564dbc1a0bc9e705b511f06", + ); }); }); diff --git a/src/proto/serializer.ts b/src/proto/serializer.ts index 9e1565b0..8852dcd7 100644 --- a/src/proto/serializer.ts +++ b/src/proto/serializer.ts @@ -25,15 +25,19 @@ export class ProtoSerializer { Nonce: transaction.getNonce().valueOf() ? transaction.getNonce().valueOf() : undefined, Value: this.serializeTransactionValue(transaction.getValue()), RcvAddr: receiverPubkey, - RcvUserName: transaction.getReceiverUsername() ? Buffer.from(transaction.getReceiverUsername()).toString("base64") : undefined, + RcvUserName: transaction.getReceiverUsername() + ? Buffer.from(transaction.getReceiverUsername()).toString("base64") + : undefined, SndAddr: senderPubkey, - SndUserName: transaction.getSenderUsername() ? Buffer.from(transaction.getSenderUsername()).toString("base64") : undefined, + SndUserName: transaction.getSenderUsername() + ? Buffer.from(transaction.getSenderUsername()).toString("base64") + : undefined, GasPrice: transaction.getGasPrice().valueOf(), GasLimit: transaction.getGasLimit().valueOf(), Data: transaction.getData().length() == 0 ? null : transaction.getData().valueOf(), ChainID: Buffer.from(transaction.getChainID().valueOf()), Version: transaction.getVersion().valueOf(), - Signature: transaction.getSignature() + Signature: transaction.getSignature(), }); if (transaction.getOptions().valueOf() !== TRANSACTION_OPTIONS_DEFAULT) { diff --git a/src/relayedTransactionV1Builder.spec.ts b/src/relayedTransactionV1Builder.spec.ts index 55bbc9c0..018ba6b0 100644 --- a/src/relayedTransactionV1Builder.spec.ts +++ b/src/relayedTransactionV1Builder.spec.ts @@ -34,7 +34,7 @@ describe("test relayed v1 transaction builder", function () { MinGasLimit: 50_000, GasPerDataByte: 1_500, GasPriceModifier: 0.01, - ChainID: "T" + ChainID: "T", }; builder.setNetworkConfig(networkConfig); assert.throw(() => builder.build(), errors.ErrInvalidRelayedV1BuilderArguments); @@ -48,7 +48,7 @@ describe("test relayed v1 transaction builder", function () { MinGasLimit: 50_000, GasPerDataByte: 1_500, GasPriceModifier: 0.01, - ChainID: "T" + ChainID: "T", }; const innerTx = new Transaction({ @@ -73,8 +73,14 @@ describe("test relayed v1 transaction builder", function () { relayedTxV1.applySignature(await alice.signer.sign(relayedTxV1.serializeForSigning())); assert.equal(relayedTxV1.getNonce().valueOf(), 2627); - assert.equal(relayedTxV1.getData().toString(), "relayedTx@7b226e6f6e6365223a3139382c2273656e646572223a2267456e574f65576d6d413063306a6b71764d354241707a61644b46574e534f69417643575163776d4750673d222c227265636569766572223a22414141414141414141414141415141414141414141414141414141414141414141414141414141432f2f383d222c2276616c7565223a302c226761735072696365223a313030303030303030302c226761734c696d6974223a36303030303030302c2264617461223a225a3256305132397564484a68593352446232356d6157633d222c227369676e6174757265223a2272525455544858677a4273496e4f6e454b6b7869642b354e66524d486e33534948314673746f577352434c434b3258514c41614f4e704449346531476173624c5150616130566f364144516d4f2b52446b6f364a43413d3d222c22636861696e4944223a2256413d3d222c2276657273696f6e223a327d"); - assert.equal(relayedTxV1.getSignature().toString("hex"), "128e7cdc14c2b9beee2f3ff7a7fa5d1f5ef31a654a0c92e223c90ab28265fa277d306f23a06536248cf9573e828017004fb639617fade4d68a37524aafca710d"); + assert.equal( + relayedTxV1.getData().toString(), + "relayedTx@7b226e6f6e6365223a3139382c2273656e646572223a2267456e574f65576d6d413063306a6b71764d354241707a61644b46574e534f69417643575163776d4750673d222c227265636569766572223a22414141414141414141414141415141414141414141414141414141414141414141414141414141432f2f383d222c2276616c7565223a302c226761735072696365223a313030303030303030302c226761734c696d6974223a36303030303030302c2264617461223a225a3256305132397564484a68593352446232356d6157633d222c227369676e6174757265223a2272525455544858677a4273496e4f6e454b6b7869642b354e66524d486e33534948314673746f577352434c434b3258514c41614f4e704449346531476173624c5150616130566f364144516d4f2b52446b6f364a43413d3d222c22636861696e4944223a2256413d3d222c2276657273696f6e223a327d", + ); + assert.equal( + relayedTxV1.getSignature().toString("hex"), + "128e7cdc14c2b9beee2f3ff7a7fa5d1f5ef31a654a0c92e223c90ab28265fa277d306f23a06536248cf9573e828017004fb639617fade4d68a37524aafca710d", + ); }); it("should compute relayed v1 transaction (with usernames)", async function () { @@ -82,7 +88,7 @@ describe("test relayed v1 transaction builder", function () { MinGasLimit: 50_000, GasPerDataByte: 1_500, GasPriceModifier: 0.01, - ChainID: "T" + ChainID: "T", }; const innerTx = new Transaction({ @@ -93,7 +99,7 @@ describe("test relayed v1 transaction builder", function () { senderUsername: "carol", receiverUsername: "alice", gasLimit: 50000, - chainID: networkConfig.ChainID + chainID: networkConfig.ChainID, }); innerTx.applySignature(await carol.signer.sign(innerTx.serializeForSigning())); @@ -109,8 +115,14 @@ describe("test relayed v1 transaction builder", function () { relayedTxV1.applySignature(await frank.signer.sign(relayedTxV1.serializeForSigning())); assert.equal(relayedTxV1.getNonce().valueOf(), 715); - assert.equal(relayedTxV1.getData().toString(), "relayedTx@7b226e6f6e6365223a3230382c2273656e646572223a227371455656633553486b6c45344a717864556e59573068397a536249533141586f3534786f32634969626f3d222c227265636569766572223a2241546c484c76396f686e63616d433877673970645168386b77704742356a6949496f3349484b594e6165453d222c2276616c7565223a313030303030303030303030303030303030302c226761735072696365223a313030303030303030302c226761734c696d6974223a35303030302c2264617461223a22222c227369676e6174757265223a226a33427a6469554144325963517473576c65707663664a6f75657a48573063316b735a424a4d6339573167435450512b6870636759457858326f6f367a4b5654347464314b4b6f79783841526a346e336474576c44413d3d222c22636861696e4944223a2256413d3d222c2276657273696f6e223a322c22736e64557365724e616d65223a22593246796232773d222c22726376557365724e616d65223a22595778705932553d227d"); - assert.equal(relayedTxV1.getSignature().toString("hex"), "3787d640e5a579e7977a4a1bcdd435ad11855632fa4a414a06fbf8355692d1a58d76ef0adbdd6ccd6bd3c329f36bd53c180d4873ec1a6c558e659aeb9ab92d00"); + assert.equal( + relayedTxV1.getData().toString(), + "relayedTx@7b226e6f6e6365223a3230382c2273656e646572223a227371455656633553486b6c45344a717864556e59573068397a536249533141586f3534786f32634969626f3d222c227265636569766572223a2241546c484c76396f686e63616d433877673970645168386b77704742356a6949496f3349484b594e6165453d222c2276616c7565223a313030303030303030303030303030303030302c226761735072696365223a313030303030303030302c226761734c696d6974223a35303030302c2264617461223a22222c227369676e6174757265223a226a33427a6469554144325963517473576c65707663664a6f75657a48573063316b735a424a4d6339573167435450512b6870636759457858326f6f367a4b5654347464314b4b6f79783841526a346e336474576c44413d3d222c22636861696e4944223a2256413d3d222c2276657273696f6e223a322c22736e64557365724e616d65223a22593246796232773d222c22726376557365724e616d65223a22595778705932553d227d", + ); + assert.equal( + relayedTxV1.getSignature().toString("hex"), + "3787d640e5a579e7977a4a1bcdd435ad11855632fa4a414a06fbf8355692d1a58d76ef0adbdd6ccd6bd3c329f36bd53c180d4873ec1a6c558e659aeb9ab92d00", + ); }); it("should compute relayed v1 transaction with big value", async function () { @@ -118,7 +130,7 @@ describe("test relayed v1 transaction builder", function () { MinGasLimit: 50_000, GasPerDataByte: 1_500, GasPriceModifier: 0.01, - ChainID: "T" + ChainID: "T", }; const innerTx = new Transaction({ @@ -129,7 +141,7 @@ describe("test relayed v1 transaction builder", function () { senderUsername: "carol", receiverUsername: "alice", gasLimit: 50000, - chainID: networkConfig.ChainID + chainID: networkConfig.ChainID, }); innerTx.applySignature(await carol.signer.sign(innerTx.serializeForSigning())); @@ -145,8 +157,14 @@ describe("test relayed v1 transaction builder", function () { relayedTxV1.applySignature(await frank.signer.sign(relayedTxV1.serializeForSigning())); assert.equal(relayedTxV1.getNonce().valueOf(), 715); - assert.equal(relayedTxV1.getData().toString(), "relayedTx@7b226e6f6e6365223a3230382c2273656e646572223a227371455656633553486b6c45344a717864556e59573068397a536249533141586f3534786f32634969626f3d222c227265636569766572223a2241546c484c76396f686e63616d433877673970645168386b77704742356a6949496f3349484b594e6165453d222c2276616c7565223a313939393939393030303030303030303030303030303030302c226761735072696365223a313030303030303030302c226761734c696d6974223a35303030302c2264617461223a22222c227369676e6174757265223a22594661677972512f726d614c7333766e7159307657553858415a7939354b4e31725738347a4f764b62376c7a3773576e2f566a546d68704378774d682b7261314e444832574d6f3965507648304f79427453776a44773d3d222c22636861696e4944223a2256413d3d222c2276657273696f6e223a322c22736e64557365724e616d65223a22593246796232773d222c22726376557365724e616d65223a22595778705932553d227d"); - assert.equal(relayedTxV1.getSignature().toString("hex"), "c0fb5cf8c0a413d6988ba35dc279c63f8849572c5f23b1cab36dcc50952dc3ed9da01068d6ac0cbde7e14167bfc2eca5164d5c2154c89eb313c9c596e3f8b801"); + assert.equal( + relayedTxV1.getData().toString(), + "relayedTx@7b226e6f6e6365223a3230382c2273656e646572223a227371455656633553486b6c45344a717864556e59573068397a536249533141586f3534786f32634969626f3d222c227265636569766572223a2241546c484c76396f686e63616d433877673970645168386b77704742356a6949496f3349484b594e6165453d222c2276616c7565223a313939393939393030303030303030303030303030303030302c226761735072696365223a313030303030303030302c226761734c696d6974223a35303030302c2264617461223a22222c227369676e6174757265223a22594661677972512f726d614c7333766e7159307657553858415a7939354b4e31725738347a4f764b62376c7a3773576e2f566a546d68704378774d682b7261314e444832574d6f3965507648304f79427453776a44773d3d222c22636861696e4944223a2256413d3d222c2276657273696f6e223a322c22736e64557365724e616d65223a22593246796232773d222c22726376557365724e616d65223a22595778705932553d227d", + ); + assert.equal( + relayedTxV1.getSignature().toString("hex"), + "c0fb5cf8c0a413d6988ba35dc279c63f8849572c5f23b1cab36dcc50952dc3ed9da01068d6ac0cbde7e14167bfc2eca5164d5c2154c89eb313c9c596e3f8b801", + ); }); it("should compute guarded inner Tx - relayed v1 transaction", async function () { @@ -154,7 +172,7 @@ describe("test relayed v1 transaction builder", function () { MinGasLimit: 50_000, GasPerDataByte: 1_500, GasPriceModifier: 0.01, - ChainID: "T" + ChainID: "T", }; const innerTx = new Transaction({ @@ -166,7 +184,7 @@ describe("test relayed v1 transaction builder", function () { data: new TransactionPayload("getContractConfig"), guardian: grace.address, version: TransactionVersion.withTxOptions(), - options: TransactionOptions.withOptions({ guarded: true }) + options: TransactionOptions.withOptions({ guarded: true }), }); innerTx.applySignature(await bob.signer.sign(innerTx.serializeForSigning())); @@ -183,8 +201,14 @@ describe("test relayed v1 transaction builder", function () { relayedTxV1.applySignature(await alice.signer.sign(relayedTxV1.serializeForSigning())); assert.equal(relayedTxV1.getNonce().valueOf(), 2627); - assert.equal(relayedTxV1.getData().toString(), "relayedTx@7b226e6f6e6365223a3139382c2273656e646572223a2267456e574f65576d6d413063306a6b71764d354241707a61644b46574e534f69417643575163776d4750673d222c227265636569766572223a22414141414141414141414146414b565841323879704877692f79693741364c64504b704f68464d386958513d222c2276616c7565223a302c226761735072696365223a313030303030303030302c226761734c696d6974223a36303030303030302c2264617461223a225a3256305132397564484a68593352446232356d6157633d222c227369676e6174757265223a224b4b78324f33383655725135416b4f465258307578327933446a384853334b373038487174344668377161557669424550716c45614e746e6158706a6f2f333651476d4a456934784435457a6c6f4f677a634d4442773d3d222c22636861696e4944223a2256413d3d222c2276657273696f6e223a322c226f7074696f6e73223a322c22677561726469616e223a22486f714c61306e655733766843716f56696c70715372744c5673774939535337586d7a563868477450684d3d222c22677561726469616e5369676e6174757265223a222b5431526f4833625a792f54423177342b6a365155477258645637457577553073753948646551626453515269463953757a686d634b705463526d58595252366c534c6652394931624d7134674730436538363741513d3d227d"); - assert.equal(relayedTxV1.getSignature().toString("hex"), "39cff9d5100e290fbc7361cb6e2402261caf864257b4116f150e0c61e7869155dff8361fa5449431eb7a8ed847c01ba9b3b5ebafe5fac1a3d40c64829d827e00"); + assert.equal( + relayedTxV1.getData().toString(), + "relayedTx@7b226e6f6e6365223a3139382c2273656e646572223a2267456e574f65576d6d413063306a6b71764d354241707a61644b46574e534f69417643575163776d4750673d222c227265636569766572223a22414141414141414141414146414b565841323879704877692f79693741364c64504b704f68464d386958513d222c2276616c7565223a302c226761735072696365223a313030303030303030302c226761734c696d6974223a36303030303030302c2264617461223a225a3256305132397564484a68593352446232356d6157633d222c227369676e6174757265223a224b4b78324f33383655725135416b4f465258307578327933446a384853334b373038487174344668377161557669424550716c45614e746e6158706a6f2f333651476d4a456934784435457a6c6f4f677a634d4442773d3d222c22636861696e4944223a2256413d3d222c2276657273696f6e223a322c226f7074696f6e73223a322c22677561726469616e223a22486f714c61306e655733766843716f56696c70715372744c5673774939535337586d7a563868477450684d3d222c22677561726469616e5369676e6174757265223a222b5431526f4833625a792f54423177342b6a365155477258645637457577553073753948646551626453515269463953757a686d634b705463526d58595252366c534c6652394931624d7134674730436538363741513d3d227d", + ); + assert.equal( + relayedTxV1.getSignature().toString("hex"), + "39cff9d5100e290fbc7361cb6e2402261caf864257b4116f150e0c61e7869155dff8361fa5449431eb7a8ed847c01ba9b3b5ebafe5fac1a3d40c64829d827e00", + ); }); it("should compute guarded inner tx and guarded relayed v1 transaction", async function () { @@ -192,7 +216,7 @@ describe("test relayed v1 transaction builder", function () { MinGasLimit: 50_000, GasPerDataByte: 1_500, GasPriceModifier: 0.01, - ChainID: "T" + ChainID: "T", }; const innerTx = new Transaction({ @@ -204,7 +228,7 @@ describe("test relayed v1 transaction builder", function () { data: new TransactionPayload("addNumber"), guardian: grace.address, version: TransactionVersion.withTxOptions(), - options: TransactionOptions.withOptions({ guarded: true }) + options: TransactionOptions.withOptions({ guarded: true }), }); innerTx.applySignature(await bob.signer.sign(innerTx.serializeForSigning())); @@ -224,7 +248,13 @@ describe("test relayed v1 transaction builder", function () { relayedTxV1.applyGuardianSignature(await frank.signer.sign(relayedTxV1.serializeForSigning())); assert.equal(relayedTxV1.getNonce().valueOf(), 2627); - assert.equal(relayedTxV1.getData().toString(), "relayedTx@7b226e6f6e6365223a3139382c2273656e646572223a2267456e574f65576d6d413063306a6b71764d354241707a61644b46574e534f69417643575163776d4750673d222c227265636569766572223a22414141414141414141414146414b565841323879704877692f79693741364c64504b704f68464d386958513d222c2276616c7565223a302c226761735072696365223a313030303030303030302c226761734c696d6974223a36303030303030302c2264617461223a225957526b546e5674596d5679222c227369676e6174757265223a223469724d4b4a656d724d375174344e7635487633544c44683775654779487045564c4371674a3677652f7a662b746a4933354975573452633458543451533433475333356158386c6a533834324a38426854645043673d3d222c22636861696e4944223a2256413d3d222c2276657273696f6e223a322c226f7074696f6e73223a322c22677561726469616e223a22486f714c61306e655733766843716f56696c70715372744c5673774939535337586d7a563868477450684d3d222c22677561726469616e5369676e6174757265223a2270424754394e674a78307539624c56796b654d78786a454865374269696c37764932324a46676f32787a6e2f496e3032463769546563356b44395045324f747065386c475335412b532f4a36417762576834446744673d3d227d"); - assert.equal(relayedTxV1.getSignature().toString("hex"), "8ede1bbeed96b102344dffeac12c2592c62b7313cdeb132e8c8bf11d2b1d3bb8189d257a6dbcc99e222393d9b9ec77656c349dae97a32e68bdebd636066bf706"); + assert.equal( + relayedTxV1.getData().toString(), + "relayedTx@7b226e6f6e6365223a3139382c2273656e646572223a2267456e574f65576d6d413063306a6b71764d354241707a61644b46574e534f69417643575163776d4750673d222c227265636569766572223a22414141414141414141414146414b565841323879704877692f79693741364c64504b704f68464d386958513d222c2276616c7565223a302c226761735072696365223a313030303030303030302c226761734c696d6974223a36303030303030302c2264617461223a225957526b546e5674596d5679222c227369676e6174757265223a223469724d4b4a656d724d375174344e7635487633544c44683775654779487045564c4371674a3677652f7a662b746a4933354975573452633458543451533433475333356158386c6a533834324a38426854645043673d3d222c22636861696e4944223a2256413d3d222c2276657273696f6e223a322c226f7074696f6e73223a322c22677561726469616e223a22486f714c61306e655733766843716f56696c70715372744c5673774939535337586d7a563868477450684d3d222c22677561726469616e5369676e6174757265223a2270424754394e674a78307539624c56796b654d78786a454865374269696c37764932324a46676f32787a6e2f496e3032463769546563356b44395045324f747065386c475335412b532f4a36417762576834446744673d3d227d", + ); + assert.equal( + relayedTxV1.getSignature().toString("hex"), + "8ede1bbeed96b102344dffeac12c2592c62b7313cdeb132e8c8bf11d2b1d3bb8189d257a6dbcc99e222393d9b9ec77656c349dae97a32e68bdebd636066bf706", + ); }); }); diff --git a/src/relayedTransactionV2Builder.spec.ts b/src/relayedTransactionV2Builder.spec.ts index b72823c2..cb4cd530 100644 --- a/src/relayedTransactionV2Builder.spec.ts +++ b/src/relayedTransactionV2Builder.spec.ts @@ -25,7 +25,7 @@ describe("test relayed v2 transaction builder", function () { MinGasLimit: 50_000, GasPerDataByte: 1_500, GasPriceModifier: 0.01, - ChainID: "T" + ChainID: "T", }; const innerTx = new Transaction({ @@ -46,7 +46,7 @@ describe("test relayed v2 transaction builder", function () { innerTx.setGasLimit({ valueOf: function () { return 10; - } + }, }); builder = builder.setNetworkConfig(networkConfig).setInnerTransactionGasLimit(10).setInnerTransaction(innerTx); assert.throw(() => builder.build(), errors.ErrGasLimitShouldBe0ForInnerTransaction); @@ -57,7 +57,7 @@ describe("test relayed v2 transaction builder", function () { MinGasLimit: 50_000, GasPerDataByte: 1_500, GasPriceModifier: 0.01, - ChainID: "T" + ChainID: "T", }; const innerTx = new Transaction({ @@ -88,8 +88,7 @@ describe("test relayed v2 transaction builder", function () { assert.equal(relayedTxV2.getVersion().valueOf(), 2); assert.equal( relayedTxV2.getData().toString(), - "relayedTxV2@000000000000000000010000000000000000000000000000000000000002ffff@0f@676574436f6e7472616374436f6e666967@fc3ed87a51ee659f937c1a1ed11c1ae677e99629fae9cc289461f033e6514d1a8cfad1144ae9c1b70f28554d196bd6ba1604240c1c1dc19c959e96c1c3b62d0c"); + "relayedTxV2@000000000000000000010000000000000000000000000000000000000002ffff@0f@676574436f6e7472616374436f6e666967@fc3ed87a51ee659f937c1a1ed11c1ae677e99629fae9cc289461f033e6514d1a8cfad1144ae9c1b70f28554d196bd6ba1604240c1c1dc19c959e96c1c3b62d0c", + ); }); }); - - diff --git a/src/signableMessage.spec.ts b/src/signableMessage.spec.ts index e8843f8f..4480b66d 100644 --- a/src/signableMessage.spec.ts +++ b/src/signableMessage.spec.ts @@ -2,7 +2,6 @@ import { assert } from "chai"; import { SignableMessage } from "./signableMessage"; import { loadTestWallets, TestWallet } from "./testutils"; - describe("test signable message", () => { let alice: TestWallet; before(async function () { @@ -13,18 +12,23 @@ describe("test signable message", () => { address: alice.address, message: Buffer.from("test message", "ascii"), signature: Buffer.from("a".repeat(128), "hex"), - signer: "ElrondWallet" + signer: "ElrondWallet", }); const jsonSM = sm.toJSON(); // We just test that the returned object contains what was passed and the hex values are prefixed with 0x - assert.deepEqual(jsonSM, { - address: 'erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th', - message: '0x74657374206d657373616765', - signature: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - version: 1, - signer: 'ElrondWallet' - }, "invalid signable message returned"); + assert.deepEqual( + jsonSM, + { + address: "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", + message: "0x74657374206d657373616765", + signature: + "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + version: 1, + signer: "ElrondWallet", + }, + "invalid signable message returned", + ); }); }); diff --git a/src/smartcontracts/codec/binary.spec.ts b/src/smartcontracts/codec/binary.spec.ts index 95d2304d..33df7e6c 100644 --- a/src/smartcontracts/codec/binary.spec.ts +++ b/src/smartcontracts/codec/binary.spec.ts @@ -1,7 +1,49 @@ import * as errors from "../../errors"; import { assert } from "chai"; import { BinaryCodec, BinaryCodecConstraints } from "./binary"; -import { AddressType, AddressValue, BigIntType, BigUIntType, BigUIntValue, BooleanType, BooleanValue, I16Type, I32Type, I64Type, I8Type, NumericalType, NumericalValue, Struct, Field, StructType, TypedValue, U16Type, U32Type, U32Value, U64Type, U64Value, U8Type, U8Value, List, ListType, EnumType, EnumVariantDefinition, EnumValue, ArrayVec, ArrayVecType, U16Value, TokenIdentifierType, TokenIdentifierValue, StringValue, StringType, BigIntValue, I64Value, I32Value, I16Value, I8Value } from "../typesystem"; +import { + AddressType, + AddressValue, + BigIntType, + BigUIntType, + BigUIntValue, + BooleanType, + BooleanValue, + I16Type, + I32Type, + I64Type, + I8Type, + NumericalType, + NumericalValue, + Struct, + Field, + StructType, + TypedValue, + U16Type, + U32Type, + U32Value, + U64Type, + U64Value, + U8Type, + U8Value, + List, + ListType, + EnumType, + EnumVariantDefinition, + EnumValue, + ArrayVec, + ArrayVecType, + U16Value, + TokenIdentifierType, + TokenIdentifierValue, + StringValue, + StringType, + BigIntValue, + I64Value, + I32Value, + I16Value, + I8Value, +} from "../typesystem"; import { isMsbOne } from "./utils"; import { Address } from "../../address"; import { BytesType, BytesValue } from "../typesystem/bytes"; @@ -24,47 +66,55 @@ describe("test binary codec (basic)", () => { let [decodedNested, nestedLength] = codec.decodeNested(Buffer.from(nested), type); assert.instanceOf(decodedNested, BooleanValue); - assert.isTrue((decodedNested).equals(value)); + assert.isTrue(decodedNested.equals(value)); assert.equal(nestedLength, 1); let decodedTop = codec.decodeTopLevel(Buffer.from(topLevel), type); assert.instanceOf(decodedTop, BooleanValue); - assert.isTrue((decodedTop).equals(value)); + assert.isTrue(decodedTop.equals(value)); } }); it("should create numeric values, encode and decode", async () => { - // Small int - checkNumerical(BigInt(42), new U8Type(), [0x2A], [0x2A]); - checkNumerical(BigInt(42), new U16Type(), [0x00, 0x2A], [0x2A]); - checkNumerical(BigInt(42), new U64Type(), [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2A], [0x2A]); - checkNumerical(BigInt(-10), new I8Type(), [0xF6], [0xF6]); - checkNumerical(BigInt(-10), new I16Type(), [0xFF, 0xF6], [0xF6]); + checkNumerical(BigInt(42), new U8Type(), [0x2a], [0x2a]); + checkNumerical(BigInt(42), new U16Type(), [0x00, 0x2a], [0x2a]); + checkNumerical(BigInt(42), new U64Type(), [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a], [0x2a]); + checkNumerical(BigInt(-10), new I8Type(), [0xf6], [0xf6]); + checkNumerical(BigInt(-10), new I16Type(), [0xff, 0xf6], [0xf6]); // BigInt checkNumerical(BigInt(0), new BigIntType(), [0, 0, 0, 0], []); checkNumerical(BigInt(1), new BigIntType(), [0, 0, 0, 1, 0x01], [0x01]); - checkNumerical(BigInt(-1), new BigIntType(), [0, 0, 0, 1, 0xFF], [0xFF]); - checkNumerical(BigInt(-2), new BigIntType(), [0, 0, 0, 1, 0xFE], [0xFE]); - checkNumerical(BigInt(127), new BigIntType(), [0, 0, 0, 1, 0x7F], [0x7F]); + checkNumerical(BigInt(-1), new BigIntType(), [0, 0, 0, 1, 0xff], [0xff]); + checkNumerical(BigInt(-2), new BigIntType(), [0, 0, 0, 1, 0xfe], [0xfe]); + checkNumerical(BigInt(127), new BigIntType(), [0, 0, 0, 1, 0x7f], [0x7f]); checkNumerical(BigInt(128), new BigIntType(), [0, 0, 0, 2, 0x00, 0x80], [0x00, 0x80]); - checkNumerical(BigInt(255), new BigIntType(), [0, 0, 0, 2, 0x00, 0xFF], [0x00, 0xFF]); + checkNumerical(BigInt(255), new BigIntType(), [0, 0, 0, 2, 0x00, 0xff], [0x00, 0xff]); checkNumerical(BigInt(256), new BigIntType(), [0, 0, 0, 2, 0x01, 0x00], [0x01, 0x00]); - checkNumerical(BigInt(-255), new BigIntType(), [0, 0, 0, 2, 0xFF, 0x01], [0xFF, 0x01]); - checkNumerical(BigInt(-257), new BigIntType(), [0, 0, 0, 2, 0xFE, 0xFF], [0xFE, 0xFF]); + checkNumerical(BigInt(-255), new BigIntType(), [0, 0, 0, 2, 0xff, 0x01], [0xff, 0x01]); + checkNumerical(BigInt(-257), new BigIntType(), [0, 0, 0, 2, 0xfe, 0xff], [0xfe, 0xff]); // Zero, fixed-size - [new U8Type(), new I8Type(), new U16Type(), new I16Type(), new U32Type(), new I32Type(), new U64Type(), new I64Type()].forEach(type => { + [ + new U8Type(), + new I8Type(), + new U16Type(), + new I16Type(), + new U32Type(), + new I32Type(), + new U64Type(), + new I64Type(), + ].forEach((type) => { checkNumerical(BigInt(0), type, Array(type.sizeInBytes!).fill(0), []); }); // Zero, arbitrary-size (big) - [new BigIntType(), new BigUIntType()].forEach(type => { + [new BigIntType(), new BigUIntType()].forEach((type) => { checkNumerical(BigInt(0), type, [0, 0, 0, 0], []); }); @@ -92,7 +142,10 @@ describe("test binary codec (basic)", () => { assert.deepEqual(new U16Value("0xabcdef"), new U16Value(BigInt(0xabcdef))); assert.deepEqual(new U8Value("0xabcdef"), new U8Value(BigInt(0xabcdef))); - assert.deepEqual(new BigIntValue(BigInt("0xabcdefabcdefabcdef")), new BigIntValue(BigInt("0xabcdefabcdefabcdef"))); + assert.deepEqual( + new BigIntValue(BigInt("0xabcdefabcdefabcdef")), + new BigIntValue(BigInt("0xabcdefabcdefabcdef")), + ); assert.deepEqual(new I64Value("0xabcdef"), new I64Value(BigInt(0xabcdef))); assert.deepEqual(new I32Value("0xabcdef"), new I32Value(BigInt(0xabcdef))); assert.deepEqual(new I16Value("0xabcdef"), new I16Value(BigInt(0xabcdef))); @@ -108,12 +161,18 @@ describe("test binary codec (basic)", () => { assert.deepEqual(codec.encodeNested(bytesValue), Buffer.from([...length, ...payload])); assert.deepEqual(codec.encodeTopLevel(bytesValue), Buffer.from(payload)); - assert.deepEqual(codec.decodeNested(Buffer.from([...length, ...payload]), new BytesType()), [bytesValue, 8]); + assert.deepEqual(codec.decodeNested(Buffer.from([...length, ...payload]), new BytesType()), [ + bytesValue, + 8, + ]); assert.deepEqual(codec.decodeTopLevel(Buffer.from(payload), new BytesType()), bytesValue); assert.deepEqual(codec.encodeNested(stringValue), Buffer.from([...length, ...payload])); assert.deepEqual(codec.encodeTopLevel(stringValue), Buffer.from(payload)); - assert.deepEqual(codec.decodeNested(Buffer.from([...length, ...payload]), new StringType()), [stringValue, 8]); + assert.deepEqual(codec.decodeNested(Buffer.from([...length, ...payload]), new StringType()), [ + stringValue, + 8, + ]); assert.deepEqual(codec.decodeTopLevel(Buffer.from(payload), new StringType()), stringValue); }); }); @@ -121,20 +180,21 @@ describe("test binary codec (basic)", () => { describe("test binary codec (advanced)", () => { it("should encode / decode lists", async () => { let codec = new BinaryCodec(); - let list = new List( - new ListType(new AddressType()), - [ - new AddressValue(new Address("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th")), - new AddressValue(new Address("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx")), - new AddressValue(new Address("erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8")) - ]); + let list = new List(new ListType(new AddressType()), [ + new AddressValue(new Address("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th")), + new AddressValue(new Address("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx")), + new AddressValue(new Address("erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8")), + ]); let bufferNested = codec.encodeNested(list); let bufferTopLevel = codec.encodeTopLevel(list); assert.equal(bufferNested.length, 4 + list.getLength() * 32); assert.equal(bufferTopLevel.length, list.getLength() * 32); - let [decodedNested, decodedNestedLength] = codec.decodeNested(bufferNested, new ListType(new AddressType())); + let [decodedNested, decodedNestedLength] = codec.decodeNested( + bufferNested, + new ListType(new AddressType()), + ); let decodedTopLevel = codec.decodeTopLevel(bufferTopLevel, new ListType(new AddressType())); assert.equal(decodedNestedLength, bufferNested.length); assert.equal(decodedNested.getLength(), 3); @@ -156,21 +216,31 @@ describe("test binary codec (advanced)", () => { let list = new List(new ListType(new U32Type()), items); - assert.throws(() => { - codec.encodeNested(list); - }, errors.ErrCodec, `List too large: ${numItems} > ${codec.constraints.maxListLength}`); + assert.throws( + () => { + codec.encodeNested(list); + }, + errors.ErrCodec, + `List too large: ${numItems} > ${codec.constraints.maxListLength}`, + ); - assert.throws(() => { - codec.encodeTopLevel(list); - }, errors.ErrCodec, `List too large: ${numItems} > ${codec.constraints.maxListLength}`); + assert.throws( + () => { + codec.encodeTopLevel(list); + }, + errors.ErrCodec, + `List too large: ${numItems} > ${codec.constraints.maxListLength}`, + ); }); it("benchmark: should work well with large lists", async function () { let numItems = 2 ** 12; - let codec = new BinaryCodec(new BinaryCodecConstraints({ - maxListLength: numItems, - maxBufferLength: numItems * 4 + 4 - })); + let codec = new BinaryCodec( + new BinaryCodecConstraints({ + maxListLength: numItems, + maxBufferLength: numItems * 4 + 4, + }), + ); let items: TypedValue[] = []; @@ -198,10 +268,7 @@ describe("test binary codec (advanced)", () => { let length = 20; let sizeOfItem = 2; // u16 let arrayType = new ArrayVecType(length, new U16Type()); - let array = new ArrayVec( - arrayType, - Array(length).fill(new U16Value(0xABBA)) - ); + let array = new ArrayVec(arrayType, Array(length).fill(new U16Value(0xabba))); let bufferNested = codec.encodeNested(array); let bufferTopLevel = codec.encodeTopLevel(array); @@ -221,18 +288,15 @@ describe("test binary codec (advanced)", () => { it("should encode / decode structs", async () => { let codec = new BinaryCodec(); - let fooType = new StructType( - "Foo", - [ - new FieldDefinition("token_identifier", "", new TokenIdentifierType()), - new FieldDefinition("ticket_price", "", new BigUIntType()), - new FieldDefinition("tickets_left", "", new U32Type()), - new FieldDefinition("deadline", "", new U64Type()), - new FieldDefinition("max_entries_per_user", "", new U32Type()), - new FieldDefinition("prize_distribution", "", new BytesType()), - new FieldDefinition("prize_pool", "", new BigUIntType()) - ] - ); + let fooType = new StructType("Foo", [ + new FieldDefinition("token_identifier", "", new TokenIdentifierType()), + new FieldDefinition("ticket_price", "", new BigUIntType()), + new FieldDefinition("tickets_left", "", new U32Type()), + new FieldDefinition("deadline", "", new U64Type()), + new FieldDefinition("max_entries_per_user", "", new U32Type()), + new FieldDefinition("prize_distribution", "", new BytesType()), + new FieldDefinition("prize_pool", "", new BigUIntType()), + ]); let fooStruct = new Struct(fooType, [ new Field(new TokenIdentifierValue("lucky-token"), "token_identifier"), @@ -241,10 +305,12 @@ describe("test binary codec (advanced)", () => { new Field(new U64Value(new BigNumber("0x000000005fc2b9db")), "deadline"), new Field(new U32Value(0xffffffff), "max_entries_per_user"), new Field(new BytesValue(Buffer.from([0x64])), "prize_distribution"), - new Field(new BigUIntValue(new BigNumber("94720000000000000000000")), "prize_pool") + new Field(new BigUIntValue(new BigNumber("94720000000000000000000")), "prize_pool"), ]); - let encodedExpected = serialized("[0000000b|6c75636b792d746f6b656e] [00000001|01] [00000000] [000000005fc2b9db] [ffffffff] [00000001|64] [0000000a|140ec80fa7ee88000000]"); + let encodedExpected = serialized( + "[0000000b|6c75636b792d746f6b656e] [00000001|01] [00000000] [000000005fc2b9db] [ffffffff] [00000001|64] [0000000a|140ec80fa7ee88000000]", + ); let encoded = codec.encodeNested(fooStruct); assert.deepEqual(encoded, encodedExpected); @@ -260,28 +326,27 @@ describe("test binary codec (advanced)", () => { deadline: new BigNumber("0x000000005fc2b9db", 16), max_entries_per_user: new BigNumber(0xffffffff), prize_distribution: Buffer.from([0x64]), - prize_pool: new BigNumber("94720000000000000000000") + prize_pool: new BigNumber("94720000000000000000000"), }); }); it("should encode / decode structs containing a TokenIdentifier", async () => { let codec = new BinaryCodec(); - let paymentType = new StructType( - "Payment", - [ - new FieldDefinition("token_identifier", "", new TokenIdentifierType()), - new FieldDefinition("nonce", "", new U64Type()), - new FieldDefinition("amount", "", new BigUIntType()), - ] - ); + let paymentType = new StructType("Payment", [ + new FieldDefinition("token_identifier", "", new TokenIdentifierType()), + new FieldDefinition("nonce", "", new U64Type()), + new FieldDefinition("amount", "", new BigUIntType()), + ]); let paymentStruct = new Struct(paymentType, [ new Field(new TokenIdentifierValue("TEST-1234"), "token_identifier"), new Field(new U64Value(new BigNumber(42)), "nonce"), - new Field(new BigUIntValue(new BigNumber("123450000000000000000")), "amount") + new Field(new BigUIntValue(new BigNumber("123450000000000000000")), "amount"), ]); - let encodedExpected = serialized("[00000009|544553542d31323334] [000000000000002a] [00000009|06b13680ef11f90000]"); + let encodedExpected = serialized( + "[00000009|544553542d31323334] [000000000000002a] [00000009|06b13680ef11f90000]", + ); let encoded = codec.encodeNested(paymentStruct); assert.deepEqual(encoded, encodedExpected); @@ -302,29 +367,29 @@ describe("test binary codec (advanced)", () => { let enumType = new EnumType("Colour", [ new EnumVariantDefinition("Orange", 0), new EnumVariantDefinition("Green", 1), - new EnumVariantDefinition("Blue", 255) + new EnumVariantDefinition("Blue", 255), ]); let orange = EnumValue.fromName(enumType, "Orange"); let green = EnumValue.fromName(enumType, "Green"); - let blue = EnumValue.fromName(enumType, "Blue") + let blue = EnumValue.fromName(enumType, "Blue"); assert.deepEqual(codec.encodeNested(orange), Buffer.from([0x00])); assert.deepEqual(codec.encodeTopLevel(orange), Buffer.from([])); assert.deepEqual(codec.encodeNested(green), Buffer.from([0x01])); assert.deepEqual(codec.encodeTopLevel(green), Buffer.from([0x01])); - assert.deepEqual(codec.encodeNested(blue), Buffer.from([0xFF])); - assert.deepEqual(codec.encodeTopLevel(blue), Buffer.from([0xFF])); + assert.deepEqual(codec.encodeNested(blue), Buffer.from([0xff])); + assert.deepEqual(codec.encodeTopLevel(blue), Buffer.from([0xff])); assert.isTrue(orange.equals(codec.decodeTopLevel(Buffer.from([]), enumType))); assert.isTrue(green.equals(codec.decodeTopLevel(Buffer.from([0x01]), enumType))); - assert.isTrue(blue.equals(codec.decodeTopLevel(Buffer.from([0xFF]), enumType))); + assert.isTrue(blue.equals(codec.decodeTopLevel(Buffer.from([0xff]), enumType))); let [decoded] = codec.decodeNested(Buffer.from([0x00]), enumType); assert.deepEqual(decoded, orange); [decoded] = codec.decodeNested(Buffer.from([0x01]), enumType); assert.deepEqual(decoded, green); - [decoded] = codec.decodeNested(Buffer.from([0xFF]), enumType); + [decoded] = codec.decodeNested(Buffer.from([0xff]), enumType); assert.deepEqual(decoded, blue); }); @@ -337,35 +402,40 @@ describe("test binary codec (advanced)", () => { new FieldDefinition("1", "green component", new U8Type()), new FieldDefinition("2", "blue component", new U8Type()), new FieldDefinition("3", "hex code", new BytesType()), - new FieldDefinition("4", "fruits", typeOfListOfStrings) + new FieldDefinition("4", "fruits", typeOfListOfStrings), ]); let blueVariant = new EnumVariantDefinition("Blue", 1, [ new FieldDefinition("0", "hex code", new BytesType()), - new FieldDefinition("1", "fruits", typeOfListOfStrings) + new FieldDefinition("1", "fruits", typeOfListOfStrings), ]); - let enumType = new EnumType("Colour", [ - orangeVariant, - blueVariant - ]); + let enumType = new EnumType("Colour", [orangeVariant, blueVariant]); let orange = new EnumValue(enumType, orangeVariant, [ new Field(new U8Value(255), "0"), new Field(new U8Value(165), "1"), new Field(new U8Value(0), "2"), new Field(BytesValue.fromUTF8("#FFA500"), "3"), - new Field(new List(typeOfListOfStrings, [BytesValue.fromUTF8("orange"), BytesValue.fromUTF8("persimmon")]), "4") + new Field( + new List(typeOfListOfStrings, [BytesValue.fromUTF8("orange"), BytesValue.fromUTF8("persimmon")]), + "4", + ), ]); let blue = new EnumValue(enumType, blueVariant, [ new Field(BytesValue.fromUTF8("#0000FF"), "0"), - new Field(new List(typeOfListOfStrings, [BytesValue.fromUTF8("blueberry"), BytesValue.fromUTF8("plum")]), "1") + new Field( + new List(typeOfListOfStrings, [BytesValue.fromUTF8("blueberry"), BytesValue.fromUTF8("plum")]), + "1", + ), ]); // Orange // [[discriminant = 0]] [R] [G] [B] [bytes for hex code] [list of 2 elements (fruits)] - let orangeEncodedNested = serialized("[[00]] [ff] [a5] [00] [00000007 | 23464641353030] [00000002 | [00000006|6f72616e6765] [00000009|70657273696d6d6f6e]]"); + let orangeEncodedNested = serialized( + "[[00]] [ff] [a5] [00] [00000007 | 23464641353030] [00000002 | [00000006|6f72616e6765] [00000009|70657273696d6d6f6e]]", + ); let orangeEncodedTopLevel = orangeEncodedNested; assert.deepEqual(codec.encodeNested(orange), orangeEncodedNested); assert.deepEqual(codec.encodeTopLevel(orange), orangeEncodedTopLevel); @@ -377,7 +447,9 @@ describe("test binary codec (advanced)", () => { // Blue // [[discriminant = 01]] [bytes for hex code] [list of 2 elements (fruits)] - let blueEncodedNested = serialized("[[01]] [00000007 | 23303030304646] [ 00000002 | [00000009|626c75656265727279] [00000004|706c756d]]"); + let blueEncodedNested = serialized( + "[[01]] [00000007 | 23303030304646] [ 00000002 | [00000009|626c75656265727279] [00000004|706c756d]]", + ); let blueEncodedTopLevel = blueEncodedNested; assert.deepEqual(codec.encodeNested(blue), blueEncodedNested); assert.deepEqual(codec.encodeTopLevel(blue), blueEncodedTopLevel); @@ -397,9 +469,9 @@ function serialized(prettyHex: string): Buffer { describe("test codec utilities", () => { it("should check whether isMsbOne", async () => { - assert.isTrue(isMsbOne(Buffer.from([0xFF]), 0)); - assert.isTrue(isMsbOne(Buffer.from([0x00, 0xFF]), 1)); - assert.isTrue(isMsbOne(Buffer.from([0x00, 0xFF, 0xFF]), 2)); + assert.isTrue(isMsbOne(Buffer.from([0xff]), 0)); + assert.isTrue(isMsbOne(Buffer.from([0x00, 0xff]), 1)); + assert.isTrue(isMsbOne(Buffer.from([0x00, 0xff, 0xff]), 2)); assert.isFalse(isMsbOne(Buffer.from([1]))); assert.isFalse(isMsbOne(Buffer.from([2]))); diff --git a/src/smartcontracts/typesystem/factory.spec.ts b/src/smartcontracts/typesystem/factory.spec.ts index afe82de1..8645a16c 100644 --- a/src/smartcontracts/typesystem/factory.spec.ts +++ b/src/smartcontracts/typesystem/factory.spec.ts @@ -10,7 +10,7 @@ describe("test factory", () => { let addresses = [ new Address("erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha"), new Address("erd1r69gk66fmedhhcg24g2c5kn2f2a5k4kvpr6jfw67dn2lyydd8cfswy6ede"), - new Address("erd1fggp5ru0jhcjrp5rjqyqrnvhr3sz3v2e0fm3ktknvlg7mcyan54qzccnan") + new Address("erd1fggp5ru0jhcjrp5rjqyqrnvhr3sz3v2e0fm3ktknvlg7mcyan54qzccnan"), ]; let list = createListOfAddresses(addresses); diff --git a/src/smartcontracts/typesystem/variadic.ts b/src/smartcontracts/typesystem/variadic.ts index b054032b..f4f21710 100644 --- a/src/smartcontracts/typesystem/variadic.ts +++ b/src/smartcontracts/typesystem/variadic.ts @@ -28,8 +28,8 @@ export class CountedVariadicType extends Type { /** * An abstraction that represents a sequence of values held under the umbrella of a variadic input / output parameter. - * - * Since at the time of constructing input parameters or decoding output parameters, the length is known, + * + * Since at the time of constructing input parameters or decoding output parameters, the length is known, * this TypedValue behaves similar to a List. */ export class VariadicValue extends TypedValue { @@ -37,7 +37,7 @@ export class VariadicValue extends TypedValue { private readonly items: TypedValue[]; /** - * + * * @param type the type of this TypedValue (an instance of VariadicType), not the type parameter of the VariadicType * @param items the items, having the type type.getFirstTypeParameter() */ @@ -75,7 +75,7 @@ export class VariadicValue extends TypedValue { } valueOf(): any[] { - return this.items.map(item => item.valueOf()); + return this.items.map((item) => item.valueOf()); } equals(other: VariadicValue): boolean { diff --git a/src/testutils/contractController.ts b/src/testutils/contractController.ts index 517d8eef..f72d3079 100644 --- a/src/testutils/contractController.ts +++ b/src/testutils/contractController.ts @@ -16,14 +16,18 @@ export class ContractController { this.parser = new ResultsParser(); this.provider = provider; this.transactionCompletionAwaiter = new TransactionWatcher({ - getTransaction: async (hash: string) => { return await provider.getTransaction(hash, true) } + getTransaction: async (hash: string) => { + return await provider.getTransaction(hash, true); + }, }); } - async deploy(transaction: Transaction): Promise<{ transactionOnNetwork: ITransactionOnNetwork, bundle: UntypedOutcomeBundle }> { + async deploy( + transaction: Transaction, + ): Promise<{ transactionOnNetwork: ITransactionOnNetwork; bundle: UntypedOutcomeBundle }> { const txHash = await this.provider.sendTransaction(transaction); Logger.info(`ContractController.deploy [begin]: transaction = ${txHash}`); - + let transactionOnNetwork = await this.transactionCompletionAwaiter.awaitCompleted(txHash); let bundle = this.parser.parseUntypedOutcome(transactionOnNetwork); @@ -31,16 +35,23 @@ export class ContractController { return { transactionOnNetwork, bundle }; } - async execute(interaction: Interaction, transaction: Transaction): Promise<{ transactionOnNetwork: ITransactionOnNetwork, bundle: TypedOutcomeBundle }> { + async execute( + interaction: Interaction, + transaction: Transaction, + ): Promise<{ transactionOnNetwork: ITransactionOnNetwork; bundle: TypedOutcomeBundle }> { const txHash = await this.provider.sendTransaction(transaction); - Logger.info(`ContractController.execute [begin]: function = ${interaction.getFunction()}, transaction = ${txHash}`); + Logger.info( + `ContractController.execute [begin]: function = ${interaction.getFunction()}, transaction = ${txHash}`, + ); interaction.check(); let transactionOnNetwork = await this.transactionCompletionAwaiter.awaitCompleted(txHash); let bundle = this.parser.parseOutcome(transactionOnNetwork, interaction.getEndpoint()); - Logger.info(`ContractController.execute [end]: function = ${interaction.getFunction()}, transaction = ${txHash}, return code = ${bundle.returnCode}`); + Logger.info( + `ContractController.execute [end]: function = ${interaction.getFunction()}, transaction = ${txHash}, return code = ${bundle.returnCode}`, + ); return { transactionOnNetwork, bundle }; } @@ -52,7 +63,9 @@ export class ContractController { let queryResponse = await this.provider.queryContract(interaction.buildQuery()); let bundle = this.parser.parseQueryResponse(queryResponse, interaction.getEndpoint()); - Logger.debug(`ContractController.query [end]: function = ${interaction.getFunction()}, return code = ${bundle.returnCode}`); + Logger.debug( + `ContractController.query [end]: function = ${interaction.getFunction()}, return code = ${bundle.returnCode}`, + ); return bundle; } } diff --git a/src/testutils/mockNetworkProvider.ts b/src/testutils/mockNetworkProvider.ts index 4a842e0c..a8e0a181 100644 --- a/src/testutils/mockNetworkProvider.ts +++ b/src/testutils/mockNetworkProvider.ts @@ -35,9 +35,15 @@ export class MockNetworkProvider { this.transactions = new Map(); this.accounts = new Map(); - this.accounts.set(MockNetworkProvider.AddressOfAlice.bech32(), { nonce: 0, balance: createAccountBalance(1000) }); + this.accounts.set(MockNetworkProvider.AddressOfAlice.bech32(), { + nonce: 0, + balance: createAccountBalance(1000), + }); this.accounts.set(MockNetworkProvider.AddressOfBob.bech32(), { nonce: 5, balance: createAccountBalance(500) }); - this.accounts.set(MockNetworkProvider.AddressOfCarol.bech32(), { nonce: 42, balance: createAccountBalance(300) }); + this.accounts.set(MockNetworkProvider.AddressOfCarol.bech32(), { + nonce: 42, + balance: createAccountBalance(300), + }); } mockUpdateAccount(address: Address, mutate: (item: IAccountOnNetwork) => void) { diff --git a/src/tokenOperations/tokenOperationsFactory.spec.ts b/src/tokenOperations/tokenOperationsFactory.spec.ts index 44c39761..f4e97ac6 100644 --- a/src/tokenOperations/tokenOperationsFactory.spec.ts +++ b/src/tokenOperations/tokenOperationsFactory.spec.ts @@ -19,13 +19,16 @@ describe("test factory", () => { tokenTicker: "TEST", tokenType: "FNG", numDecimals: 2, - transactionNonce: 42 + transactionNonce: 42, }); - assert.equal(transaction.getData().toString(), "registerAndSetAllRoles@54455354@54455354@464e47@02") + assert.equal(transaction.getData().toString(), "registerAndSetAllRoles@54455354@54455354@464e47@02"); assert.equal(transaction.getNonce(), 42); assert.equal(transaction.getSender().toString(), frank.address.toString()); - assert.equal(transaction.getReceiver().toString(), "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"); + assert.equal( + transaction.getReceiver().toString(), + "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", + ); }); it("should create ", () => { @@ -41,13 +44,19 @@ describe("test factory", () => { canChangeOwner: true, canUpgrade: false, canAddSpecialRoles: false, - transactionNonce: 42 + transactionNonce: 42, }); - assert.equal(transaction.getData().toString(), "issue@4652414e4b@4652414e4b@64@@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365") + assert.equal( + transaction.getData().toString(), + "issue@4652414e4b@4652414e4b@64@@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365", + ); assert.equal(transaction.getNonce(), 42); assert.equal(transaction.getSender().toString(), frank.address.toString()); - assert.equal(transaction.getReceiver().toString(), "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"); + assert.equal( + transaction.getReceiver().toString(), + "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", + ); }); it("should create ", () => { @@ -62,13 +71,19 @@ describe("test factory", () => { canChangeOwner: true, canUpgrade: false, canAddSpecialRoles: false, - transactionNonce: 42 + transactionNonce: 42, }); - assert.equal(transaction.getData().toString(), "issueSemiFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365") + assert.equal( + transaction.getData().toString(), + "issueSemiFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365", + ); assert.equal(transaction.getNonce(), 42); assert.equal(transaction.getSender().toString(), frank.address.toString()); - assert.equal(transaction.getReceiver().toString(), "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"); + assert.equal( + transaction.getReceiver().toString(), + "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", + ); }); it("should create ", () => { @@ -83,13 +98,19 @@ describe("test factory", () => { canChangeOwner: true, canUpgrade: false, canAddSpecialRoles: false, - transactionNonce: 42 + transactionNonce: 42, }); - assert.equal(transaction.getData().toString(), "issueNonFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365") + assert.equal( + transaction.getData().toString(), + "issueNonFungible@4652414e4b@4652414e4b@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365", + ); assert.equal(transaction.getNonce(), 42); assert.equal(transaction.getSender().toString(), frank.address.toString()); - assert.equal(transaction.getReceiver().toString(), "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"); + assert.equal( + transaction.getReceiver().toString(), + "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", + ); }); it("should create ", () => { @@ -105,13 +126,19 @@ describe("test factory", () => { canChangeOwner: true, canUpgrade: false, canAddSpecialRoles: false, - transactionNonce: 42 + transactionNonce: 42, }); - assert.equal(transaction.getData().toString(), "registerMetaESDT@4652414e4b@4652414e4b@0a@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365") + assert.equal( + transaction.getData().toString(), + "registerMetaESDT@4652414e4b@4652414e4b@0a@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e5472616e736665724e4654437265617465526f6c65@74727565@63616e4368616e67654f776e6572@74727565@63616e55706772616465@66616c7365@63616e4164645370656369616c526f6c6573@66616c7365", + ); assert.equal(transaction.getNonce(), 42); assert.equal(transaction.getSender().toString(), frank.address.toString()); - assert.equal(transaction.getReceiver().toString(), "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"); + assert.equal( + transaction.getReceiver().toString(), + "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", + ); }); it("should create ", () => { @@ -124,13 +151,19 @@ describe("test factory", () => { addRoleNFTUpdateAttributes: true, addRoleNFTAddURI: true, addRoleESDTTransferRole: false, - transactionNonce: 42 + transactionNonce: 42, }); - assert.equal(transaction.getData().toString(), "setSpecialRole@4652414e4b2d313163653365@1e8a8b6b49de5b7be10aaa158a5a6a4abb4b56cc08f524bb5e6cd5f211ad3e13@45534454526f6c654e4654437265617465@45534454526f6c654e465455706461746541747472696275746573@45534454526f6c654e4654416464555249"); + assert.equal( + transaction.getData().toString(), + "setSpecialRole@4652414e4b2d313163653365@1e8a8b6b49de5b7be10aaa158a5a6a4abb4b56cc08f524bb5e6cd5f211ad3e13@45534454526f6c654e4654437265617465@45534454526f6c654e465455706461746541747472696275746573@45534454526f6c654e4654416464555249", + ); assert.equal(transaction.getNonce(), 42); assert.equal(transaction.getSender().toString(), frank.address.toString()); - assert.equal(transaction.getReceiver().toString(), "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"); + assert.equal( + transaction.getReceiver().toString(), + "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", + ); }); it("should create ", () => { @@ -143,10 +176,13 @@ describe("test factory", () => { hash: "abba", attributes: Buffer.from("test"), uris: ["a", "b"], - transactionNonce: 42 + transactionNonce: 42, }); - assert.equal(transaction.getData().toString(), "ESDTNFTCreate@4652414e4b2d616139653864@01@74657374@03e8@61626261@74657374@61@62"); + assert.equal( + transaction.getData().toString(), + "ESDTNFTCreate@4652414e4b2d616139653864@01@74657374@03e8@61626261@74657374@61@62", + ); assert.equal(transaction.getNonce(), 42); assert.equal(transaction.getSender().toString(), grace.address.toString()); assert.equal(transaction.getReceiver().toString(), grace.address.toString()); diff --git a/src/tokenOperations/tokenOperationsFactoryConfig.ts b/src/tokenOperations/tokenOperationsFactoryConfig.ts index e1ebb54d..5a346685 100644 --- a/src/tokenOperations/tokenOperationsFactoryConfig.ts +++ b/src/tokenOperations/tokenOperationsFactoryConfig.ts @@ -25,7 +25,7 @@ export class TokenOperationsFactoryConfig { gasLimitStorePerByte: IGasLimit = 50000; issueCost: BigNumber.Value = "50000000000000000"; esdtContractAddress: IAddress = Address.fromBech32( - "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" + "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", ); constructor(chainID: IChainID) { diff --git a/src/tokenOperations/tokenOperationsOutcomeParser.spec.ts b/src/tokenOperations/tokenOperationsOutcomeParser.spec.ts index edabb2ae..ec3c5077 100644 --- a/src/tokenOperations/tokenOperationsOutcomeParser.spec.ts +++ b/src/tokenOperations/tokenOperationsOutcomeParser.spec.ts @@ -21,10 +21,10 @@ describe("test parsers", () => { address: frank.address, identifier: "issue", topics: [createTopic(Buffer.from("FOOBAR"))], - data: "" - } - ] - } + data: "", + }, + ], + }, }); assert.equal(outcome.tokenIdentifier, "FOOBAR"); @@ -44,12 +44,12 @@ describe("test parsers", () => { createTopic(Buffer.from("")), createTopic(Buffer.from("")), createTopic(Buffer.from("ESDTRoleLocalMint")), - createTopic(Buffer.from("ESDTRoleLocalBurn")) + createTopic(Buffer.from("ESDTRoleLocalBurn")), ], - data: "" - } - ] - } + data: "", + }, + ], + }, }); assert.equal(outcome.tokenIdentifier, "FOOBAR"); @@ -71,10 +71,10 @@ describe("test parsers", () => { createTopic(Buffer.from("")), createTopic(bigIntToBuffer("200")), ], - data: "" - } - ] - } + data: "", + }, + ], + }, }); assert.equal(outcome.tokenIdentifier, "FOOBAR"); @@ -97,10 +97,10 @@ describe("test parsers", () => { createTopic(bigIntToBuffer("42")), createTopic(bigIntToBuffer("1")), ], - data: "" - } - ] - } + data: "", + }, + ], + }, }); assert.equal(outcome.tokenIdentifier, "FOOBAR"); @@ -110,7 +110,7 @@ describe("test parsers", () => { function createTopic(value: Buffer): any { return { - valueOf: () => value + valueOf: () => value, }; } }); diff --git a/src/transactionWatcher.spec.ts b/src/transactionWatcher.spec.ts index 7d957420..fbcfae2e 100644 --- a/src/transactionWatcher.spec.ts +++ b/src/transactionWatcher.spec.ts @@ -4,26 +4,34 @@ import { MarkCompleted, MockNetworkProvider, Wait } from "./testutils"; import { TransactionHash } from "./transaction"; import { TransactionWatcher } from "./transactionWatcher"; - describe("test transactionWatcher", () => { it("should await status == executed using hash", async () => { let hash = new TransactionHash("abbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"); let provider = new MockNetworkProvider(); let watcher = new TransactionWatcher(provider, { pollingIntervalMilliseconds: 42, - timeoutMilliseconds: 42 * 42 + timeoutMilliseconds: 42 * 42, }); let dummyTransaction = { - getHash: () => hash - } + getHash: () => hash, + }; - provider.mockPutTransaction(hash, new TransactionOnNetwork({ - status: new TransactionStatus("unknown") - })); + provider.mockPutTransaction( + hash, + new TransactionOnNetwork({ + status: new TransactionStatus("unknown"), + }), + ); await Promise.all([ - provider.mockTransactionTimelineByHash(hash, [new Wait(40), new TransactionStatus("pending"), new Wait(40), new TransactionStatus("executed"), new MarkCompleted()]), - watcher.awaitCompleted(dummyTransaction.getHash().hex()) + provider.mockTransactionTimelineByHash(hash, [ + new Wait(40), + new TransactionStatus("pending"), + new Wait(40), + new TransactionStatus("executed"), + new MarkCompleted(), + ]), + watcher.awaitCompleted(dummyTransaction.getHash().hex()), ]); assert.isTrue((await provider.getTransactionStatus(hash.hex())).isExecuted()); @@ -34,19 +42,28 @@ describe("test transactionWatcher", () => { let provider = new MockNetworkProvider(); let watcher = new TransactionWatcher(provider, { pollingIntervalMilliseconds: 42, - timeoutMilliseconds: 42 * 42 + timeoutMilliseconds: 42 * 42, }); let dummyTransaction = { - getHash: () => hash - } + getHash: () => hash, + }; - provider.mockPutTransaction(hash, new TransactionOnNetwork({ - status: new TransactionStatus("unknown") - })); + provider.mockPutTransaction( + hash, + new TransactionOnNetwork({ + status: new TransactionStatus("unknown"), + }), + ); await Promise.all([ - provider.mockTransactionTimelineByHash(hash, [new Wait(40), new TransactionStatus("pending"), new Wait(40), new TransactionStatus("executed"), new MarkCompleted()]), - watcher.awaitCompleted(dummyTransaction) + provider.mockTransactionTimelineByHash(hash, [ + new Wait(40), + new TransactionStatus("pending"), + new Wait(40), + new TransactionStatus("executed"), + new MarkCompleted(), + ]), + watcher.awaitCompleted(dummyTransaction), ]); assert.isTrue((await provider.getTransactionStatus(hash.hex())).isExecuted()); diff --git a/src/transferTransactionsFactory.spec.ts b/src/transferTransactionsFactory.spec.ts index 66b91fe1..39e6f96d 100644 --- a/src/transferTransactionsFactory.spec.ts +++ b/src/transferTransactionsFactory.spec.ts @@ -14,11 +14,17 @@ describe("test transaction factory", () => { sender: Address.fromBech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), receiver: new Address("erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha"), data: new TransactionPayload("hello"), - chainID: "D" + chainID: "D", }); - assert.equal(transactionWithData.getSender().bech32(), "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"); - assert.equal(transactionWithData.getReceiver().bech32(), "erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha"); + assert.equal( + transactionWithData.getSender().bech32(), + "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", + ); + assert.equal( + transactionWithData.getReceiver().bech32(), + "erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha", + ); assert.equal(transactionWithData.getValue(), "10500000000000000000"); assert.equal(transactionWithData.getGasLimit(), 50000 + 5 * 1500); assert.equal(transactionWithData.getData().toString(), "hello"); @@ -28,11 +34,17 @@ describe("test transaction factory", () => { value: TokenTransfer.egldFromAmount(10.5), sender: Address.fromBech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), receiver: new Address("erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha"), - chainID: "D" + chainID: "D", }); - assert.equal(transactionWithoutData.getSender().bech32(), "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"); - assert.equal(transactionWithoutData.getReceiver().bech32(), "erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha"); + assert.equal( + transactionWithoutData.getSender().bech32(), + "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", + ); + assert.equal( + transactionWithoutData.getReceiver().bech32(), + "erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha", + ); assert.equal(transactionWithoutData.getValue(), "10500000000000000000"); assert.equal(transactionWithoutData.getGasLimit(), 50000); assert.equal(transactionWithoutData.getData().toString(), ""); @@ -44,11 +56,17 @@ describe("test transaction factory", () => { tokenTransfer: TokenTransfer.fungibleFromAmount("TEST-8b028f", "100.00", 2), sender: Address.fromBech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), receiver: Address.fromBech32("erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha"), - chainID: "D" + chainID: "D", }); - assert.equal(transaction.getSender().bech32(), "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"); - assert.equal(transaction.getReceiver().bech32(), "erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha"); + assert.equal( + transaction.getSender().bech32(), + "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", + ); + assert.equal( + transaction.getReceiver().bech32(), + "erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha", + ); assert.equal(transaction.getValue(), ""); assert.equal(transaction.getGasLimit(), 50000 + 40 * 1500 + 200000 + 100000); assert.equal(transaction.getData().toString(), "ESDTTransfer@544553542d386230323866@2710"); @@ -60,14 +78,23 @@ describe("test transaction factory", () => { tokenTransfer: TokenTransfer.nonFungible("TEST-38f249", 1), destination: new Address("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"), sender: new Address("erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha"), - chainID: "D" + chainID: "D", }); - assert.equal(transaction.getSender().bech32(), "erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha"); - assert.equal(transaction.getReceiver().bech32(), "erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha"); + assert.equal( + transaction.getSender().bech32(), + "erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha", + ); + assert.equal( + transaction.getReceiver().bech32(), + "erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha", + ); assert.equal(transaction.getValue(), ""); assert.equal(transaction.getGasLimit(), 50000 + 109 * 1500 + 200000 + 800000); - assert.equal(transaction.getData().toString(), "ESDTNFTTransfer@544553542d333866323439@01@01@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8"); + assert.equal( + transaction.getData().toString(), + "ESDTNFTTransfer@544553542d333866323439@01@01@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8", + ); assert.equal(transaction.getChainID(), "D"); }); @@ -75,18 +102,27 @@ describe("test transaction factory", () => { const transaction = factory.createMultiESDTNFTTransfer({ tokenTransfers: [ TokenTransfer.nonFungible("FOO-38f249", 1), - TokenTransfer.fungibleFromAmount("BAR-c80d29", "10.00", 18) + TokenTransfer.fungibleFromAmount("BAR-c80d29", "10.00", 18), ], destination: new Address("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"), sender: new Address("erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha"), - chainID: "D" + chainID: "D", }); - assert.equal(transaction.getSender().bech32(), "erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha"); - assert.equal(transaction.getReceiver().bech32(), "erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha"); + assert.equal( + transaction.getSender().bech32(), + "erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha", + ); + assert.equal( + transaction.getReceiver().bech32(), + "erd1dc3yzxxeq69wvf583gw0h67td226gu2ahpk3k50qdgzzym8npltq7ndgha", + ); assert.equal(transaction.getValue(), ""); assert.equal(transaction.getGasLimit(), 50000 + 154 * 1500 + (200000 + 800000) * 2); - assert.equal(transaction.getData().toString(), "MultiESDTNFTTransfer@0139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1@02@464f4f2d333866323439@01@01@4241522d633830643239@@8ac7230489e80000"); + assert.equal( + transaction.getData().toString(), + "MultiESDTNFTTransfer@0139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1@02@464f4f2d333866323439@01@01@4241522d633830643239@@8ac7230489e80000", + ); assert.equal(transaction.getChainID(), "D"); }); });