diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 000716fb3..f7d5af46d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -102,7 +102,7 @@ jobs: id: start-local-node if: ${{ steps.build-sdk.conclusion == 'success' && !cancelled() && always() }} run: | - npx @hashgraph/hedera-local start -d -—network-tag=0.49.0-alpha.5 --balance=100000 + npx @hashgraph/hedera-local start -d --network-tag=0.49.1 --balance=100000 # Wait for the network to fully start sleep 30 diff --git a/src/query/Query.js b/src/query/Query.js index 660f2a9be..27992332f 100644 --- a/src/query/Query.js +++ b/src/query/Query.js @@ -442,34 +442,26 @@ export default class Query extends Executable { responseType: HashgraphProto.proto.ResponseType.ANSWER_ONLY, }; - if (this._isPaymentRequired() && this._paymentTransactions != null) { - if (this._nodeAccountIds.locked) { - header.payment = - this._paymentTransactions[this._nodeAccountIds.index]; - } else { - const logId = this._getLogId(); - const nodeId = this._nodeAccountIds.current; - const paymentTransactionId = - /** @type {import("../transaction/TransactionId.js").default} */ ( - this._paymentTransactionId - ); - const paymentAmount = /** @type {Hbar} */ (this._queryPayment); - - if (this._logger) { - this._logger.debug( - `[${logId}] making a payment transaction for node ${nodeId.toString()} and transaction ID ${paymentTransactionId.toString()} with amount ${paymentAmount.toString()}`, - ); - } + const logId = this._getLogId(); + const nodeId = this._nodeAccountIds.current; + const paymentTransactionId = TransactionId.generate( + this._operator ? this._operator.accountId : new AccountId(0), + ); + const paymentAmount = /** @type {Hbar} */ (this._queryPayment); - header.payment = await _makePaymentTransaction( - paymentTransactionId, - nodeId, - this._isPaymentRequired() ? this._operator : null, - paymentAmount, - ); - } + if (this._logger) { + this._logger.debug( + `[${logId}] making a payment transaction for node ${nodeId.toString()} and transaction ID ${paymentTransactionId.toString()} with amount ${paymentAmount.toString()}`, + ); } + header.payment = await _makePaymentTransaction( + paymentTransactionId, + nodeId, + this._isPaymentRequired() ? this._operator : null, + paymentAmount, + ); + return this._onMakeRequest(header); } diff --git a/test/integration/AccountCreateIntegrationTest.js b/test/integration/AccountCreateIntegrationTest.js index a8060cb2c..2f150ada4 100644 --- a/test/integration/AccountCreateIntegrationTest.js +++ b/test/integration/AccountCreateIntegrationTest.js @@ -141,8 +141,7 @@ describe("AccountCreate", function () { it("should error when key is not set", async function () { this.timeout(15000); - - let err = false; + let status; try { const response = await new AccountCreateTransaction() @@ -151,12 +150,10 @@ describe("AccountCreate", function () { await response.getReceipt(env.client); } catch (error) { - err = error.toString().includes(Status.KeyRequired.toString()); + status = error.status; } - if (!err) { - throw new Error("account creation did not error"); - } + expect(status).to.be.eql(Status.KeyRequired); }); it("should be able to sign transaction and verify transaction signtatures", async function () { @@ -203,6 +200,7 @@ describe("AccountCreate", function () { }); it("should create account with a single key passed to `KeyList`", async function () { + this.timeout(15000); const publicKey = PrivateKey.generateED25519().publicKey; const thresholdKey = new KeyList(publicKey, 1); diff --git a/test/integration/AccountDeleteIntegrationTest.js b/test/integration/AccountDeleteIntegrationTest.js index acba5dc3f..abea8abd2 100644 --- a/test/integration/AccountDeleteIntegrationTest.js +++ b/test/integration/AccountDeleteIntegrationTest.js @@ -95,8 +95,7 @@ describe("AccountDelete", function () { it("should error with no account ID set", async function () { this.timeout(120000); - - let err = false; + let status; try { await ( @@ -106,14 +105,10 @@ describe("AccountDelete", function () { .execute(env.client) ).getReceipt(env.client); } catch (error) { - err = error - .toString() - .includes(Status.AccountIdDoesNotExist.toString()); + status = error.status; } - if (!err) { - throw new Error("account deletion did not error"); - } + expect(status).to.be.eql(Status.AccountIdDoesNotExist); }); after(async function () { diff --git a/test/integration/AccountUpdateIntegrationTest.js b/test/integration/AccountUpdateIntegrationTest.js index 512e5a237..bcc9bb7de 100644 --- a/test/integration/AccountUpdateIntegrationTest.js +++ b/test/integration/AccountUpdateIntegrationTest.js @@ -16,6 +16,7 @@ describe("AccountUpdate", function () { let env; before(async function () { + this.timeout(120000); env = await IntegrationTestEnv.new(); }); @@ -189,8 +190,7 @@ describe("AccountUpdate", function () { it("should error when account ID is not set", async function () { this.timeout(120000); - - let err = false; + let status; try { await ( @@ -199,14 +199,10 @@ describe("AccountUpdate", function () { .execute(env.client) ).getReceipt(env.client); } catch (error) { - err = error - .toString() - .includes(Status.AccountIdDoesNotExist.toString()); + status = error.status; } - if (!err) { - throw new Error("account update did not error"); - } + expect(status).to.be.eql(Status.AccountIdDoesNotExist); }); it("should execute with only account ID", async function () { diff --git a/test/integration/ContractCallIntegrationTest.js b/test/integration/ContractCallIntegrationTest.js index ff5798b04..253d917e7 100644 --- a/test/integration/ContractCallIntegrationTest.js +++ b/test/integration/ContractCallIntegrationTest.js @@ -8,15 +8,11 @@ import { FileDeleteTransaction, Hbar, Status, - PrivateKey, - FileAppendTransaction, } from "../../src/exports.js"; import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js"; const smartContractBytecode = "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; -const readDataBytecode = - "0x608060405234801561001057600080fd5b5061026c806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806304806dd61461003b5780634278774714610064575b600080fd5b61004e610049366004610178565b610084565b60405161005b91906101a2565b60405180910390f35b610077610072366004610178565b610101565b60405161005b91906101f1565b606060008262ffffff1667ffffffffffffffff8111156100b457634e487b7160e01b600052604160045260246000fd5b6040519080825280602002602001820160405280156100f957816020015b60408051808201909152600080825260208201528152602001906001900390816100d25790505b509392505050565b606060008262ffffff1667ffffffffffffffff81111561013157634e487b7160e01b600052604160045260246000fd5b6040519080825280602002602001820160405280156100f957816020015b60408051602081019091526000815281526020019060019003908161014f579050509392505050565b600060208284031215610189578081fd5b813562ffffff8116811461019b578182fd5b9392505050565b602080825282518282018190526000919060409081850190868401855b828110156101e4578151805185528601518685015292840192908501906001016101bf565b5091979650505050505050565b6020808252825182820181905260009190848201906040850190845b8181101561022a578351518352928401929184019160010161020d565b5090969550505050505056fea26469706673582212201dc78aeb6e1955ac889c23cf72d0595af987863764ccb6270c7825992093969264736f6c63430008040033"; describe("ContractCallIntegration", function () { let env; @@ -316,87 +312,65 @@ describe("ContractCallIntegration", function () { } }); - it("should mark as busy when network node takes longer than 10s to execute the transaction", async function () { + it("should return error when the gas is not set", async function () { this.timeout(120000); - const myPrivateKey = PrivateKey.generateED25519(); - const env = await IntegrationTestEnv.new(); - const client = env.client; - // Create a file on Hedera and store the bytecode - const fileCreateTx = new FileCreateTransaction() - .setKeys([myPrivateKey]) - .freezeWith(client); - const fileCreateSign = await fileCreateTx.sign(myPrivateKey); - const fileCreateSubmit = await fileCreateSign.execute(client); - const fileCreateRx = await fileCreateSubmit.getReceipt(client); - const bytecodeFileId = fileCreateRx.fileId; - console.log(`The bytecode file ID is: ${bytecodeFileId} \n`); - - //Append contents to the file - const fileAppendTx = new FileAppendTransaction() - .setFileId(bytecodeFileId) - .setContents(readDataBytecode) - .setMaxChunks(10) - .freezeWith(client); - const fileAppendSign = await fileAppendTx.sign(myPrivateKey); - const fileAppendSubmit = await fileAppendSign.execute(client); - const fileAppendRx = await fileAppendSubmit.getReceipt(client); - console.log("Status of file append is", fileAppendRx.status.toString()); - - // Instantiate the contract instance - const contractTx = await new ContractCreateTransaction() - //Set the file ID of the Hedera file storing the bytecode - .setBytecodeFileId(bytecodeFileId) - //Set the gas to instantiate the contract - .setGas(100000) - //Provide the constructor parameters for the contract - .setConstructorParameters(); - - //Submit the transaction to the Hedera test network - const contractResponse = await contractTx.execute(client); - - //Get the receipt of the file create transaction - const contractReceipt = await contractResponse.getReceipt(client); - - expect(contractReceipt.contractId).to.not.be.null; - expect( - contractReceipt.contractId != null - ? contractReceipt.contractId.num > 0 - : false, - ).to.be.true; - - const contractId = contractReceipt.contractId; + const operatorKey = env.operatorKey.publicKey; - let err = false; - try { - const contractQuery = await new ContractCallQuery() - //Set the gas for the query - .setGas(16000000) - //Set the contract ID to return the request for - .setContractId(contractId) - //Set the contract function to call - .setFunction( - "getLotsOfData", - new ContractFunctionParameters().addUint24(17000), + const response = await new FileCreateTransaction() + .setKeys([operatorKey]) + .setContents(smartContractBytecode) + .execute(env.client); + + let receipt = await response.getReceipt(env.client); + + expect(receipt.fileId).to.not.be.null; + expect(receipt.fileId != null ? receipt.fileId.num > 0 : false).to.be + .true; + + const file = receipt.fileId; + + receipt = await ( + await new ContractCreateTransaction() + .setAdminKey(operatorKey) + .setGas(200000) + .setConstructorParameters( + new ContractFunctionParameters().addString( + "Hello from Hedera.", + ), ) - //Set the query payment for the node returning the request - //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(35)); - - //Submit to a Hedera network - // const txResponse = await contractQuery.execute(client); - // const txResponse2 = await contractQuery2.execute(client); - const txResponse = await contractQuery.execute(client); - console.log("Res:", txResponse.getUint32(1)); + .setBytecodeFileId(file) + .setContractMemo("[e2e::ContractCreateTransaction]") + .execute(env.client) + ).getReceipt(env.client); + + expect(receipt.contractId).to.not.be.null; + expect(receipt.contractId != null ? receipt.contractId.num > 0 : false) + .to.be.true; + + const contract = receipt.contractId; + + try { + await new ContractCallQuery() + .setContractId(contract) + .setFunction("getMessage") + .execute(env.client); } catch (error) { - err = error; + expect(error.status).to.be.eql(Status.InsufficientGas); } - expect(err.toString()).to.includes("BUSY"); - if (!err) { - throw new Error("query did not error"); - } - await client.close(); + await ( + await new ContractDeleteTransaction() + .setContractId(contract) + .setTransferAccountId(env.client.operatorAccountId) + .execute(env.client) + ).getReceipt(env.client); + + await ( + await new FileDeleteTransaction() + .setFileId(file) + .execute(env.client) + ).getReceipt(env.client); }); after(async function () { diff --git a/test/integration/ContractCreateIntegrationTest.js b/test/integration/ContractCreateIntegrationTest.js index 922141fa2..6e00e2c6b 100644 --- a/test/integration/ContractCreateIntegrationTest.js +++ b/test/integration/ContractCreateIntegrationTest.js @@ -90,79 +90,6 @@ describe("ContractCreate", function () { ).getReceipt(env.client); }); - it("should be able to create without admin key", async function () { - this.timeout(120000); - - const operatorKey = env.operatorKey.publicKey; - - let response = await new FileCreateTransaction() - .setKeys([operatorKey]) - .setContents(smartContractBytecode) - .execute(env.client); - - let receipt = await response.getReceipt(env.client); - - expect(receipt.fileId).to.not.be.null; - expect(receipt.fileId != null ? receipt.fileId.num > 0 : false).to.be - .true; - - const file = receipt.fileId; - - response = await new ContractCreateTransaction() - .setGas(200000) - .setConstructorParameters( - new ContractFunctionParameters().addString( - "Hello from Hedera.", - ), - ) - .setBytecodeFileId(file) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(env.client); - - receipt = await response.getReceipt(env.client); - - expect(receipt.contractId).to.not.be.null; - expect(receipt.contractId != null ? receipt.contractId.num > 0 : false) - .to.be.true; - - let contract = receipt.contractId; - - let info = await new ContractInfoQuery() - .setContractId(contract) - .setQueryPayment(new Hbar(1)) - .execute(env.client); - - expect(info.contractId.toString()).to.be.equal(contract.toString()); - expect(info.accountId).to.be.not.null; - expect( - info.contractId != null ? info.contractId.toString() : "", - ).to.be.equal(contract.toString()); - expect(info.adminKey).to.be.not.null; - // expect(info.adminKey.toString()).to.be.equal( - // info.contractId.toString() - // ); - expect(info.storage.toInt()).to.be.equal(128); - expect(info.contractMemo).to.be.equal( - "[e2e::ContractCreateTransaction]", - ); - - let err = false; - - try { - await ( - await new ContractDeleteTransaction() - .setContractId(contract) - .execute(env.client) - ).getReceipt(env.client); - } catch (error) { - err = error.toString().includes(Status.ModifyingImmutableContract); - } - - if (!err) { - throw new Error("contract deletion did not error"); - } - }); - it("should error when gas is not set", async function () { this.timeout(120000); diff --git a/test/integration/ContractDeleteIntegrationTest.js b/test/integration/ContractDeleteIntegrationTest.js index 65ef2f420..7b10b278f 100644 --- a/test/integration/ContractDeleteIntegrationTest.js +++ b/test/integration/ContractDeleteIntegrationTest.js @@ -140,6 +140,76 @@ describe("ContractDelete", function () { throw new Error("contact deletion did not error"); } }); + + it("should create contract without admin key which can NOT be deleted", async function () { + this.timeout(120000); + + const operatorKey = env.operatorKey.publicKey; + + let response = await new FileCreateTransaction() + .setKeys([operatorKey]) + .setContents(smartContractBytecode) + .execute(env.client); + + let receipt = await response.getReceipt(env.client); + + expect(receipt.fileId).to.not.be.null; + expect(receipt.fileId != null ? receipt.fileId.num > 0 : false).to.be + .true; + + const file = receipt.fileId; + + response = await new ContractCreateTransaction() + .setGas(200000) + .setConstructorParameters( + new ContractFunctionParameters().addString( + "Hello from Hedera.", + ), + ) + .setBytecodeFileId(file) + .setContractMemo("[e2e::ContractCreateTransaction]") + .execute(env.client); + + receipt = await response.getReceipt(env.client); + + expect(receipt.contractId).to.not.be.null; + expect(receipt.contractId != null ? receipt.contractId.num > 0 : false) + .to.be.true; + + let contract = receipt.contractId; + + let info = await new ContractInfoQuery() + .setContractId(contract) + .setQueryPayment(new Hbar(1)) + .execute(env.client); + + expect(info.contractId.toString()).to.be.equal(contract.toString()); + expect(info.accountId).to.be.not.null; + expect( + info.contractId != null ? info.contractId.toString() : "", + ).to.be.equal(contract.toString()); + expect(info.adminKey).to.be.not.null; + expect(info.storage.toInt()).to.be.equal(128); + expect(info.contractMemo).to.be.equal( + "[e2e::ContractCreateTransaction]", + ); + + let status; + + try { + await ( + await new ContractDeleteTransaction() + .setContractId(contract) + .setTransferAccountId(env.client.operatorAccountId) + .execute(env.client) + ).getReceipt(env.client); + } catch (error) { + status = error.status; + } + + expect(status).to.be.equal(Status.ModifyingImmutableContract); + }); + after(async function () { await env.close(); }); diff --git a/test/integration/ContractFunctionParametersIntegrationTest.js b/test/integration/ContractFunctionParametersIntegrationTest.js index 91d510f98..990919d2a 100644 --- a/test/integration/ContractFunctionParametersIntegrationTest.js +++ b/test/integration/ContractFunctionParametersIntegrationTest.js @@ -122,7 +122,8 @@ describe("ContractFunctionParameters", function () { let newContractId; before(async function () { - env = await IntegrationTestEnv.new({ balance: 10000 }); + this.timeout(120000); + env = await IntegrationTestEnv.new({ balance: 100000 }); // Create a file on Hedera and store the bytecode const fileCreateTx = new FileCreateTransaction() .setKeys([env.operatorKey]) @@ -148,7 +149,7 @@ describe("ContractFunctionParameters", function () { ); // Instantiate the contract instance - const contractTx = await new ContractCreateTransaction() + const contractTx = new ContractCreateTransaction() //Set the file ID of the Hedera file storing the bytecode .setBytecodeFileId(bytecodeFileId) //Set the gas to instantiate the contract @@ -171,6 +172,7 @@ describe("ContractFunctionParameters", function () { bitSizes.forEach((bitSize) => { describe(`Tests for addInt${bitSize} method`, function () { + this.timeout(120000); it( getDescription( EXTREMUM.MIN, @@ -179,9 +181,10 @@ describe("ContractFunctionParameters", function () { METHOD_TYPE.INT, ), async function () { - const contractQuery = await new ContractCallQuery() + this.timeout(120000); + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -193,7 +196,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -213,9 +216,10 @@ describe("ContractFunctionParameters", function () { METHOD_TYPE.INT, ), async function () { - const contractQuery = await new ContractCallQuery() + this.timeout(120000); + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -227,7 +231,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -248,9 +252,10 @@ describe("ContractFunctionParameters", function () { METHOD_TYPE.INT, ), async function () { - const contractQuery = await new ContractCallQuery() + this.timeout(120000); + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -262,7 +267,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -281,9 +286,10 @@ describe("ContractFunctionParameters", function () { METHOD_TYPE.INT, ), async function () { - const contractQuery = await new ContractCallQuery() + this.timeout(120000); + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -295,7 +301,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -317,9 +323,10 @@ describe("ContractFunctionParameters", function () { METHOD_TYPE.INT, ), async function () { - const contractQuery = await new ContractCallQuery() + this.timeout(120000); + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -331,7 +338,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -352,9 +359,10 @@ describe("ContractFunctionParameters", function () { METHOD_TYPE.INT, ), async function () { - const contractQuery = await new ContractCallQuery() + this.timeout(120000); + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -366,7 +374,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -380,6 +388,7 @@ describe("ContractFunctionParameters", function () { }); describe(`Tests for addInt${bitSize}Array method`, function () { + this.timeout(120000); it( getDescriptionForArrayMethod( bitSize, @@ -387,10 +396,11 @@ describe("ContractFunctionParameters", function () { METHOD_TYPE.INT, ), async function () { + this.timeout(120000); const arr = createArray(bitSize, INPUT_TYPE.NUMBER); - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -402,7 +412,8 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); + //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); const result = txResponse.getResult([`int${bitSize}[]`])[0]; @@ -424,9 +435,9 @@ describe("ContractFunctionParameters", function () { ), async function () { const arr = createArray(bitSize, INPUT_TYPE.BIG_NUMBER); - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -438,7 +449,8 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); + //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); const result = txResponse.getResult([`int${bitSize}[]`])[0]; @@ -460,9 +472,9 @@ describe("ContractFunctionParameters", function () { ), async function () { const arr = createArray(bitSize, INPUT_TYPE.LONG); - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -474,7 +486,8 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); + //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); const result = txResponse.getResult([`int${bitSize}[]`])[0]; @@ -489,9 +502,9 @@ describe("ContractFunctionParameters", function () { ); it(`addInt${bitSize}Array method should return an empty array`, async function () { - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -506,7 +519,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -516,9 +529,9 @@ describe("ContractFunctionParameters", function () { it(`addInt${bitSize}Array method should throw an error`, async function () { try { - await new ContractCallQuery() + new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -530,7 +543,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); } catch (error) { expect(error).to.be.instanceOf(Error); expect(error.message).to.be.equal(REQUIRE_ARRAY_ERROR); @@ -547,9 +560,9 @@ describe("ContractFunctionParameters", function () { METHOD_TYPE.UINT, ), async function () { - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -561,7 +574,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -582,9 +595,9 @@ describe("ContractFunctionParameters", function () { METHOD_TYPE.UINT, ), async function () { - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -596,7 +609,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -618,9 +631,9 @@ describe("ContractFunctionParameters", function () { METHOD_TYPE.UINT, ), async function () { - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -632,7 +645,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -655,9 +668,9 @@ describe("ContractFunctionParameters", function () { async function () { const range = calculateRange(bitSize, INPUT_TYPE.NUMBER); const arr = [0, range.min + range.max]; - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -669,7 +682,8 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); + //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); const result = txResponse.getResult([ @@ -692,9 +706,9 @@ describe("ContractFunctionParameters", function () { ), async function () { const arr = [0, new BigNumber(2).pow(bitSize - 1).minus(1)]; - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -706,7 +720,8 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); + //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); const result = txResponse.getResult([ @@ -730,9 +745,9 @@ describe("ContractFunctionParameters", function () { async function () { const range = calculateRange(bitSize, INPUT_TYPE.NUMBER); const arr = [0, new Long(range.min + range.max)]; - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -744,7 +759,8 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); + //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); const result = txResponse.getResult([ @@ -761,9 +777,9 @@ describe("ContractFunctionParameters", function () { ); it(`addUint${bitSize}Array method should return an empty array`, async function () { - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -778,7 +794,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -788,9 +804,9 @@ describe("ContractFunctionParameters", function () { it(`addUint${bitSize}Array method should throw an error`, async function () { try { - await new ContractCallQuery() + new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -802,7 +818,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); } catch (error) { expect(error).to.be.instanceOf(Error); expect(error.message).to.be.equal(REQUIRE_ARRAY_ERROR); @@ -812,9 +828,9 @@ describe("ContractFunctionParameters", function () { }); it("should return the right min multiple int8 value", async function () { - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -824,7 +840,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -834,9 +850,9 @@ describe("ContractFunctionParameters", function () { }); it("should work the right way with 0 uint32 value", async function () { - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -846,7 +862,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -855,9 +871,9 @@ describe("ContractFunctionParameters", function () { }); it("should return the right multiple values", async function () { - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -867,7 +883,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -879,9 +895,9 @@ describe("ContractFunctionParameters", function () { }); it("should return the right multiple int40 values", async function () { - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -891,7 +907,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -901,9 +917,9 @@ describe("ContractFunctionParameters", function () { }); it("should return the right zero uint256 value", async function () { - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -916,7 +932,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -928,9 +944,9 @@ describe("ContractFunctionParameters", function () { }); it("should return the right 20 decimal uint256 value", async function () { - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -943,7 +959,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); @@ -955,9 +971,9 @@ describe("ContractFunctionParameters", function () { }); it("should return the again right uint256 value", async function () { - const contractQuery = await new ContractCallQuery() + const contractQuery = new ContractCallQuery() //Set the gas for the query - .setGas(15000000) + .setGas(12000000) //Set the contract ID to return the request for .setContractId(newContractId) //Set the contract function to call @@ -970,7 +986,7 @@ describe("ContractFunctionParameters", function () { ) //Set the query payment for the node returning the request //This value must cover the cost of the request otherwise will fail - .setQueryPayment(new Hbar(15)); + .setQueryPayment(new Hbar(10)); //Submit to a Hedera network const txResponse = await contractQuery.execute(env.client); diff --git a/test/integration/FileContentsIntegrationTest.js b/test/integration/FileContentsIntegrationTest.js index e6a4ae91e..7036d3f2e 100644 --- a/test/integration/FileContentsIntegrationTest.js +++ b/test/integration/FileContentsIntegrationTest.js @@ -85,9 +85,7 @@ describe("FileContents", function () { let err = false; try { - await new FileContentsQuery() - .setQueryPayment(new Hbar(1)) - .execute(env.client); + await new FileContentsQuery().execute(env.client); } catch (error) { err = error.toString().includes(Status.InvalidFileId); } diff --git a/test/integration/FileCreateIntegrationTest.js b/test/integration/FileCreateIntegrationTest.js index 291df89e4..61ca554de 100644 --- a/test/integration/FileCreateIntegrationTest.js +++ b/test/integration/FileCreateIntegrationTest.js @@ -91,26 +91,23 @@ describe("FileCreate", function () { it("should error with too large expiration time", async function () { this.timeout(120000); - + let status; + const timestamp = new Timestamp(Date.now() / 1000 + 9999999999, 0); const operatorKey = env.operatorKey.publicKey; - let err = false; - try { await ( await new FileCreateTransaction() .setKeys([operatorKey]) .setContents("[e2e::FileCreateTransaction]") - .setExpirationTime(new Timestamp(Date.now() + 99999999, 0)) + .setExpirationTime(timestamp) .execute(env.client) ).getReceipt(env.client); } catch (error) { - err = error.toString().includes(Status.AutorenewDurationNotInRange); + status = error.status; } - if (!err) { - throw new Error("file creation did not error"); - } + expect(status).to.be.eql(Status.AutorenewDurationNotInRange); }); after(async function () { diff --git a/test/integration/FreezeTransactionIntegrationTest.js b/test/integration/FreezeTransactionIntegrationTest.js index 20c15c52f..09dce30cc 100644 --- a/test/integration/FreezeTransactionIntegrationTest.js +++ b/test/integration/FreezeTransactionIntegrationTest.js @@ -34,16 +34,6 @@ describe("FreezeTransaction", function () { expect(error.status).to.be.equal(Status.NotSupported); } - // At the moment the API is not supported that's why the following lines are commented out. - // Once supported the try/catch block above should be removed. - // The status from execution of the transaction is code 13 which means NOT_SUPPORTED. - - // const response = await transaction.execute(client) - // expect(response).to.be.instanceof(TransactionResponse) - // const receipt = await response.getReceipt(client) - // expect(receipt).to.be.instanceof(TransactionReceipt) - // expect(receipt.status.toString).to.be.instanceof(Status.Success) - client.close(); }); }); diff --git a/test/integration/NftAllowancesIntegrationTest.js b/test/integration/NftAllowancesIntegrationTest.js index efabc0c14..5da8ad536 100644 --- a/test/integration/NftAllowancesIntegrationTest.js +++ b/test/integration/NftAllowancesIntegrationTest.js @@ -25,7 +25,7 @@ describe("TokenNftAllowances", function () { it("Cannot transfer on behalf of `spender` account without allowance approval", async function () { this.timeout(120000); - + let status; const spenderKey = PrivateKey.generateED25519(); const spenderAccountId = ( await ( @@ -84,7 +84,6 @@ describe("TokenNftAllowances", function () { const nft1 = new NftId(nftTokenId, serials[0]); - let err = false; const onBehalfOfTransactionId = TransactionId.generate(spenderAccountId); try { @@ -102,10 +101,10 @@ describe("TokenNftAllowances", function () { ).execute(env.client) ).getReceipt(env.client); } catch (error) { - err = error.toString().includes(Status.SpenderDoesNotHaveAllowance); + status = error.status; } - expect(err).to.be.true; + expect(status).to.be.eql(Status.SpenderDoesNotHaveAllowance); }); it("Cannot transfer on behalf of `spender` account after removing the allowance approval", async function () { diff --git a/test/integration/SystemIntegrationTest.js b/test/integration/SystemIntegrationTest.js index 2c4b6922c..9125ca6c3 100644 --- a/test/integration/SystemIntegrationTest.js +++ b/test/integration/SystemIntegrationTest.js @@ -13,9 +13,8 @@ describe("SystemIntegration", function () { env = await IntegrationTestEnv.new(); }); - it("should be executable", async function () { + it("should be executable when file id is not set", async function () { this.timeout(120000); - let errorThrown = false; try { @@ -28,7 +27,11 @@ describe("SystemIntegration", function () { } expect(errorThrown).to.be.true; - errorThrown = false; + }); + + it("should be executable when contract id is not set", async function () { + this.timeout(120000); + let errorThrown = false; try { await new SystemDeleteTransaction() @@ -40,7 +43,11 @@ describe("SystemIntegration", function () { } expect(errorThrown).to.be.true; - errorThrown = false; + }); + + it("should be executable when file id and expiratiion time are not set", async function () { + this.timeout(120000); + let errorThrown = false; try { await new SystemDeleteTransaction() @@ -51,7 +58,11 @@ describe("SystemIntegration", function () { } expect(errorThrown).to.be.true; - errorThrown = false; + }); + + it("should be executable when contract id and expiration time are not set", async function () { + this.timeout(120000); + let errorThrown = false; try { await new SystemDeleteTransaction() diff --git a/test/integration/TokenAllowancesIntegrationTest.js b/test/integration/TokenAllowancesIntegrationTest.js index b62de9054..c5474e41a 100644 --- a/test/integration/TokenAllowancesIntegrationTest.js +++ b/test/integration/TokenAllowancesIntegrationTest.js @@ -29,7 +29,7 @@ describe("TokenAllowances", function () { it("Cannot transfer on behalf of `spender` account without allowance approval", async function () { this.timeout(120000); - + let status; const spenderKey = PrivateKey.generateED25519(); const spenderAccountId = ( await ( @@ -76,7 +76,6 @@ describe("TokenAllowances", function () { ).execute(env.client) ).getReceipt(env.client); - let err = false; const onBehalfOfTransactionId = TransactionId.generate(spenderAccountId); try { @@ -91,10 +90,10 @@ describe("TokenAllowances", function () { ).execute(env.client) ).getReceipt(env.client); } catch (error) { - err = error.toString().includes(Status.SpenderDoesNotHaveAllowance); + status = error.status; } - expect(err).to.be.true; + expect(status).to.be.eql(Status.SpenderDoesNotHaveAllowance); }); it("Can transfer on behalf of `spender` account with allowance approval", async function () { diff --git a/test/integration/TokenUpdateIntegrationTest.js b/test/integration/TokenUpdateIntegrationTest.js index cfc5ce553..087f06b8f 100644 --- a/test/integration/TokenUpdateIntegrationTest.js +++ b/test/integration/TokenUpdateIntegrationTest.js @@ -307,7 +307,7 @@ describe("TokenUpdate", function () { } }); - it("should be exectuable when updating immutable token, but not setting any fields besides token ID", async function () { + it("should return error when updating immutable token", async function () { this.timeout(120000); let status; @@ -322,6 +322,7 @@ describe("TokenUpdate", function () { const token = (await response.getReceipt(env.client)).tokenId; + try { await ( await new TokenUpdateTransaction() .setTokenId(token) @@ -331,7 +332,8 @@ describe("TokenUpdate", function () { status = error.status; } - expect(status).to.eql(Status.TokenIsImmutable); + expect(status).to.be.eql(Status.TokenIsImmutable); + }); it("should error when admin key does not sign transaction", async function () { diff --git a/test/integration/TransactionReceiptIntegrationTest.js b/test/integration/TransactionReceiptIntegrationTest.js index 2c54010a3..2670c7a9f 100644 --- a/test/integration/TransactionReceiptIntegrationTest.js +++ b/test/integration/TransactionReceiptIntegrationTest.js @@ -11,6 +11,7 @@ import { import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js"; describe("TransactionReceipt", function () { + this.timeout(120000); let env; before(async function () { diff --git a/test/unit/AccountInfoMocking.js b/test/unit/AccountInfoMocking.js index 2a532216b..7af12a535 100644 --- a/test/unit/AccountInfoMocking.js +++ b/test/unit/AccountInfoMocking.js @@ -118,6 +118,8 @@ describe("AccountInfoMocking", function () { it("should error when cost is greater than max cost set on client", async function () { this.timeout(10000); + let errorName; + ({ client, servers } = await Mocker.withResponses([ [ { response: ACCOUNT_INFO_QUERY_COST_RESPONSE }, @@ -127,17 +129,15 @@ describe("AccountInfoMocking", function () { client.setDefaultMaxQueryPayment(Hbar.fromTinybars(10)); - let err = false; - try { await new AccountInfoQuery() .setAccountId("0.0.3") .execute(client, 1); } catch (error) { - err = error instanceof MaxQueryPaymentExceeded; + errorName = error.name; } - expect(err).to.be.true; + expect(errorName).to.be.eql("MaxQueryPaymentExceededError"); }); it("setQueryPayemnt() avoids querying actual cost", async function () {