-
Notifications
You must be signed in to change notification settings - Fork 48
Fixes for gas estimation when performing SC transactions #672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.DeployMultisigContractInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
|
||
| const transaction = await this.multisigFactory.createTransactionForDeploy(sender.address, options); | ||
|
|
||
| transaction.guardian = options.guardian ?? Address.empty(); | ||
|
|
@@ -318,6 +319,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.ProposeAddBoardMemberInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForProposeAddBoardMember( | ||
| sender.address, | ||
| options, | ||
|
|
@@ -336,6 +338,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.ProposeAddProposerInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForProposeAddProposer(sender.address, options); | ||
|
|
||
| await this.setupAndSignTransaction(transaction, options, nonce, sender); | ||
|
|
@@ -351,6 +354,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.ProposeRemoveUserInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForProposeRemoveUser(sender.address, options); | ||
|
|
||
| await this.setupAndSignTransaction(transaction, options, nonce, sender); | ||
|
|
@@ -366,6 +370,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.ProposeChangeQuorumInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForProposeChangeQuorum(sender.address, options); | ||
|
|
||
| await this.setupAndSignTransaction(transaction, options, nonce, sender); | ||
|
|
@@ -390,6 +395,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.ActionInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForSignAction(sender.address, options); | ||
|
|
||
| await this.setupAndSignTransaction(transaction, options, nonce, sender); | ||
|
|
@@ -405,6 +411,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.ActionInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForPerformAction(sender.address, options); | ||
|
|
||
| await this.setupAndSignTransaction(transaction, options, nonce, sender); | ||
|
|
@@ -429,6 +436,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.ActionInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForUnsign(sender.address, options); | ||
|
|
||
| await this.setupAndSignTransaction(transaction, options, nonce, sender); | ||
|
|
@@ -444,6 +452,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.ActionInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForDiscardAction(sender.address, options); | ||
|
|
||
| await this.setupAndSignTransaction(transaction, options, nonce, sender); | ||
|
|
@@ -459,6 +468,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.DepositExecuteInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForDeposit(sender.address, options); | ||
|
|
||
| await this.setupAndSignTransaction(transaction, options, nonce, sender); | ||
|
|
@@ -474,6 +484,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.ProposeTransferExecuteInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForProposeTransferExecute( | ||
| sender.address, | ||
| options, | ||
|
|
@@ -492,6 +503,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.ProposeTransferExecuteEsdtInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForProposeTransferExecuteEsdt( | ||
| sender.address, | ||
| options, | ||
|
|
@@ -510,6 +522,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.ProposeAsyncCallInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForProposeAsyncCall(sender.address, options); | ||
|
|
||
| await this.setupAndSignTransaction(transaction, options, nonce, sender); | ||
|
|
@@ -525,6 +538,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.ProposeContractDeployFromSourceInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForProposeContractDeployFromSource( | ||
| sender.address, | ||
| options, | ||
|
|
@@ -543,6 +557,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.ProposeContractUpgradeFromSourceInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForProposeContractUpgradeFromSource( | ||
| sender.address, | ||
| options, | ||
|
|
@@ -561,6 +576,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.GroupInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForSignBatch(sender.address, options); | ||
|
|
||
| await this.setupAndSignTransaction(transaction, options, nonce, sender); | ||
|
|
@@ -576,6 +592,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.ActionInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForSignAndPerform(sender.address, options); | ||
|
|
||
| await this.setupAndSignTransaction(transaction, options, nonce, sender); | ||
|
|
@@ -591,6 +608,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.UnsignForOutdatedBoardMembersInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForUnsignForOutdatedBoardMembers( | ||
| sender.address, | ||
| options, | ||
|
|
@@ -609,6 +627,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.GroupInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForPerformBatch(sender.address, options); | ||
|
|
||
| await this.setupAndSignTransaction(transaction, options, nonce, sender); | ||
|
|
@@ -624,6 +643,7 @@ export class MultisigController extends BaseController { | |
| nonce: bigint, | ||
| options: resources.DiscardBatchInput & BaseControllerInput, | ||
| ): Promise<Transaction> { | ||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||
| const transaction = await this.multisigFactory.createTransactionForDiscardBatch(sender.address, options); | ||
|
|
||
| await this.setupAndSignTransaction(transaction, options, nonce, sender); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,8 @@ import { Abi, BigUIntValue, BooleanValue, BytesValue, Tuple, U16Value, U64Value | |
| import { Account } from "../accounts"; | ||
| import { Address, SmartContractQueryResponse } from "../core"; | ||
| import { GasLimitEstimator } from "../gasEstimator"; | ||
| import { MockNetworkProvider, getTestWalletsPath, loadAbiRegistry } from "../testutils"; | ||
| import { ProxyNetworkProvider } from "../networkProviders"; | ||
| import { MockNetworkProvider, getTestWalletsPath, loadAbiRegistry, loadContractCode } from "../testutils"; | ||
| import { bigIntToBuffer } from "../tokenOperations/codec"; | ||
| import { SmartContractController } from "./smartContractController"; | ||
|
|
||
|
|
@@ -276,5 +277,26 @@ describe("test smart contract queries controller", () => { | |
|
|
||
| assert.equal(transaction.gasLimit, 123456789n); | ||
| }); | ||
|
|
||
| it("should estimate gas using gasLimitEstimator", async function () { | ||
| const alice = await Account.newFromPem(`${getTestWalletsPath()}/alice.pem`); | ||
| const networkProvider = new ProxyNetworkProvider("https://devnet-gateway.multiversx.com"); | ||
|
|
||
| const gasLimitEstimator = new GasLimitEstimator({ networkProvider: networkProvider }); | ||
| const controller = new SmartContractController({ | ||
| chainID: "D", | ||
| networkProvider: networkProvider, | ||
| gasLimitEstimator: gasLimitEstimator, | ||
|
Comment on lines
+283
to
+289
|
||
| }); | ||
|
|
||
| const bytecode = await loadContractCode("src/testdata/adder.wasm"); | ||
|
|
||
| const transaction = await controller.createTransactionForDeploy(alice, 0n, { | ||
| bytecode: bytecode, | ||
| arguments: [new BigUIntValue(0)], | ||
| }); | ||
|
|
||
| assert.isTrue(transaction.gasLimit > 0n); | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -48,8 +48,9 @@ export class SmartContractController extends BaseController { | |||||
| nonce: bigint, | ||||||
| options: resources.ContractDeployInput & BaseControllerInput, | ||||||
| ): Promise<Transaction> { | ||||||
| const transaction = await this.factory.createTransactionForDeploy(sender.address, options); | ||||||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | ||||||
|
||||||
| options.gasLimit = options.gasLimit ? options.gasLimit : 0n; | |
| options.gasLimit ??= 0n; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test uses a live network provider, making the spec non-deterministic and potentially flaky (also fetching account nonce from network). Use a mock provider that simulates gas estimation and account queries, or convert this into an integration test that only runs when an env flag is set.