Skip to content

Commit c42d4ec

Browse files
authored
Merge branch 'main' into fix-managed-decimal-nested-decoding
2 parents 89cbd69 + 36e47af commit c42d4ec

File tree

6 files changed

+99
-9
lines changed

6 files changed

+99
-9
lines changed

src/multisig/multisigController.spec.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { assert } from "chai";
2+
import { Account } from "../accounts";
23
import { Address, CodeMetadata, SmartContractQueryResponse } from "../core";
3-
import { loadAbiRegistry, MockNetworkProvider } from "../testutils";
4+
import { GasLimitEstimator } from "../gasEstimator";
5+
import { ProxyNetworkProvider } from "../networkProviders";
6+
import { getTestWalletsPath, loadAbiRegistry, loadContractCode, MockNetworkProvider } from "../testutils";
47
import { MultisigController } from "./multisigController";
58
import * as resources from "./resources";
69

@@ -20,6 +23,48 @@ describe("test multisig controller query methods", () => {
2023
});
2124
});
2225

26+
it("should create transaction for deploy multisig contract", async function () {
27+
const alice = await Account.newFromPem(`${getTestWalletsPath()}/alice.pem`);
28+
29+
const boardMemberOne = Address.newFromBech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx");
30+
const boardMemberTwo = Address.newFromBech32("erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8");
31+
32+
const board = [boardMemberOne, boardMemberTwo];
33+
34+
const bytecode = await loadContractCode("src/testdata/multisig-full.wasm");
35+
const abi = await loadAbiRegistry("src/testdata/multisig-full.abi.json");
36+
37+
const networkProvider = new ProxyNetworkProvider("https://devnet-gateway.multiversx.com");
38+
const gasLimitEstimator = new GasLimitEstimator({ networkProvider: networkProvider });
39+
40+
const controller = new MultisigController({
41+
chainID: "D",
42+
networkProvider: networkProvider,
43+
abi: abi,
44+
gasLimitEstimator: gasLimitEstimator,
45+
});
46+
47+
alice.nonce = (await networkProvider.getAccount(alice.address)).nonce;
48+
49+
const transaction = await controller.createTransactionForDeploy(alice, alice.getNonceThenIncrement(), {
50+
bytecode: bytecode,
51+
quorum: 2,
52+
board,
53+
});
54+
const bytecodeHex = Buffer.from(bytecode).toString("hex");
55+
assert.equal(transaction.sender.toBech32(), alice.address.toBech32());
56+
assert.equal(transaction.receiver.toBech32(), "erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu");
57+
assert.equal(transaction.value, 0n);
58+
assert.equal(transaction.chainID, "D");
59+
assert.isTrue(transaction.gasLimit > 0n);
60+
assert.deepEqual(
61+
Buffer.from(transaction.data),
62+
Buffer.from(
63+
`${bytecodeHex}@0500@0504@02@8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8@b2a11555ce521e4944e09ab17549d85b487dcd26c84b5017a39e31a3670889ba`,
64+
),
65+
);
66+
});
67+
2368
it("getQuorum returns the quorum value", async function () {
2469
networkProvider.mockQueryContractOnFunction(
2570
"getQuorum",

src/multisig/multisigController.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class MultisigController extends BaseController {
5151
nonce: bigint,
5252
options: resources.DeployMultisigContractInput & BaseControllerInput,
5353
): Promise<Transaction> {
54+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
5455
const transaction = await this.multisigFactory.createTransactionForDeploy(sender.address, options);
5556

5657
transaction.guardian = options.guardian ?? Address.empty();
@@ -318,6 +319,7 @@ export class MultisigController extends BaseController {
318319
nonce: bigint,
319320
options: resources.ProposeAddBoardMemberInput & BaseControllerInput,
320321
): Promise<Transaction> {
322+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
321323
const transaction = await this.multisigFactory.createTransactionForProposeAddBoardMember(
322324
sender.address,
323325
options,
@@ -336,6 +338,7 @@ export class MultisigController extends BaseController {
336338
nonce: bigint,
337339
options: resources.ProposeAddProposerInput & BaseControllerInput,
338340
): Promise<Transaction> {
341+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
339342
const transaction = await this.multisigFactory.createTransactionForProposeAddProposer(sender.address, options);
340343

341344
await this.setupAndSignTransaction(transaction, options, nonce, sender);
@@ -351,6 +354,7 @@ export class MultisigController extends BaseController {
351354
nonce: bigint,
352355
options: resources.ProposeRemoveUserInput & BaseControllerInput,
353356
): Promise<Transaction> {
357+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
354358
const transaction = await this.multisigFactory.createTransactionForProposeRemoveUser(sender.address, options);
355359

356360
await this.setupAndSignTransaction(transaction, options, nonce, sender);
@@ -366,6 +370,7 @@ export class MultisigController extends BaseController {
366370
nonce: bigint,
367371
options: resources.ProposeChangeQuorumInput & BaseControllerInput,
368372
): Promise<Transaction> {
373+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
369374
const transaction = await this.multisigFactory.createTransactionForProposeChangeQuorum(sender.address, options);
370375

371376
await this.setupAndSignTransaction(transaction, options, nonce, sender);
@@ -390,6 +395,7 @@ export class MultisigController extends BaseController {
390395
nonce: bigint,
391396
options: resources.ActionInput & BaseControllerInput,
392397
): Promise<Transaction> {
398+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
393399
const transaction = await this.multisigFactory.createTransactionForSignAction(sender.address, options);
394400

395401
await this.setupAndSignTransaction(transaction, options, nonce, sender);
@@ -405,6 +411,7 @@ export class MultisigController extends BaseController {
405411
nonce: bigint,
406412
options: resources.ActionInput & BaseControllerInput,
407413
): Promise<Transaction> {
414+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
408415
const transaction = await this.multisigFactory.createTransactionForPerformAction(sender.address, options);
409416

410417
await this.setupAndSignTransaction(transaction, options, nonce, sender);
@@ -429,6 +436,7 @@ export class MultisigController extends BaseController {
429436
nonce: bigint,
430437
options: resources.ActionInput & BaseControllerInput,
431438
): Promise<Transaction> {
439+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
432440
const transaction = await this.multisigFactory.createTransactionForUnsign(sender.address, options);
433441

434442
await this.setupAndSignTransaction(transaction, options, nonce, sender);
@@ -444,6 +452,7 @@ export class MultisigController extends BaseController {
444452
nonce: bigint,
445453
options: resources.ActionInput & BaseControllerInput,
446454
): Promise<Transaction> {
455+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
447456
const transaction = await this.multisigFactory.createTransactionForDiscardAction(sender.address, options);
448457

449458
await this.setupAndSignTransaction(transaction, options, nonce, sender);
@@ -459,6 +468,7 @@ export class MultisigController extends BaseController {
459468
nonce: bigint,
460469
options: resources.DepositExecuteInput & BaseControllerInput,
461470
): Promise<Transaction> {
471+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
462472
const transaction = await this.multisigFactory.createTransactionForDeposit(sender.address, options);
463473

464474
await this.setupAndSignTransaction(transaction, options, nonce, sender);
@@ -474,6 +484,7 @@ export class MultisigController extends BaseController {
474484
nonce: bigint,
475485
options: resources.ProposeTransferExecuteInput & BaseControllerInput,
476486
): Promise<Transaction> {
487+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
477488
const transaction = await this.multisigFactory.createTransactionForProposeTransferExecute(
478489
sender.address,
479490
options,
@@ -492,6 +503,7 @@ export class MultisigController extends BaseController {
492503
nonce: bigint,
493504
options: resources.ProposeTransferExecuteEsdtInput & BaseControllerInput,
494505
): Promise<Transaction> {
506+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
495507
const transaction = await this.multisigFactory.createTransactionForProposeTransferExecuteEsdt(
496508
sender.address,
497509
options,
@@ -510,6 +522,7 @@ export class MultisigController extends BaseController {
510522
nonce: bigint,
511523
options: resources.ProposeAsyncCallInput & BaseControllerInput,
512524
): Promise<Transaction> {
525+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
513526
const transaction = await this.multisigFactory.createTransactionForProposeAsyncCall(sender.address, options);
514527

515528
await this.setupAndSignTransaction(transaction, options, nonce, sender);
@@ -525,6 +538,7 @@ export class MultisigController extends BaseController {
525538
nonce: bigint,
526539
options: resources.ProposeContractDeployFromSourceInput & BaseControllerInput,
527540
): Promise<Transaction> {
541+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
528542
const transaction = await this.multisigFactory.createTransactionForProposeContractDeployFromSource(
529543
sender.address,
530544
options,
@@ -543,6 +557,7 @@ export class MultisigController extends BaseController {
543557
nonce: bigint,
544558
options: resources.ProposeContractUpgradeFromSourceInput & BaseControllerInput,
545559
): Promise<Transaction> {
560+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
546561
const transaction = await this.multisigFactory.createTransactionForProposeContractUpgradeFromSource(
547562
sender.address,
548563
options,
@@ -561,6 +576,7 @@ export class MultisigController extends BaseController {
561576
nonce: bigint,
562577
options: resources.GroupInput & BaseControllerInput,
563578
): Promise<Transaction> {
579+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
564580
const transaction = await this.multisigFactory.createTransactionForSignBatch(sender.address, options);
565581

566582
await this.setupAndSignTransaction(transaction, options, nonce, sender);
@@ -576,6 +592,7 @@ export class MultisigController extends BaseController {
576592
nonce: bigint,
577593
options: resources.ActionInput & BaseControllerInput,
578594
): Promise<Transaction> {
595+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
579596
const transaction = await this.multisigFactory.createTransactionForSignAndPerform(sender.address, options);
580597

581598
await this.setupAndSignTransaction(transaction, options, nonce, sender);
@@ -591,6 +608,7 @@ export class MultisigController extends BaseController {
591608
nonce: bigint,
592609
options: resources.UnsignForOutdatedBoardMembersInput & BaseControllerInput,
593610
): Promise<Transaction> {
611+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
594612
const transaction = await this.multisigFactory.createTransactionForUnsignForOutdatedBoardMembers(
595613
sender.address,
596614
options,
@@ -609,6 +627,7 @@ export class MultisigController extends BaseController {
609627
nonce: bigint,
610628
options: resources.GroupInput & BaseControllerInput,
611629
): Promise<Transaction> {
630+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
612631
const transaction = await this.multisigFactory.createTransactionForPerformBatch(sender.address, options);
613632

614633
await this.setupAndSignTransaction(transaction, options, nonce, sender);
@@ -624,6 +643,7 @@ export class MultisigController extends BaseController {
624643
nonce: bigint,
625644
options: resources.DiscardBatchInput & BaseControllerInput,
626645
): Promise<Transaction> {
646+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
627647
const transaction = await this.multisigFactory.createTransactionForDiscardBatch(sender.address, options);
628648

629649
await this.setupAndSignTransaction(transaction, options, nonce, sender);

src/smartContracts/smartContractController.spec.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { Abi, BigUIntValue, BooleanValue, BytesValue, Tuple, U16Value, U64Value
44
import { Account } from "../accounts";
55
import { Address, SmartContractQueryResponse } from "../core";
66
import { GasLimitEstimator } from "../gasEstimator";
7-
import { MockNetworkProvider, getTestWalletsPath, loadAbiRegistry } from "../testutils";
7+
import { ProxyNetworkProvider } from "../networkProviders";
8+
import { MockNetworkProvider, getTestWalletsPath, loadAbiRegistry, loadContractCode } from "../testutils";
89
import { bigIntToBuffer } from "../tokenOperations/codec";
910
import { SmartContractController } from "./smartContractController";
1011

@@ -276,5 +277,26 @@ describe("test smart contract queries controller", () => {
276277

277278
assert.equal(transaction.gasLimit, 123456789n);
278279
});
280+
281+
it("should estimate gas using gasLimitEstimator", async function () {
282+
const alice = await Account.newFromPem(`${getTestWalletsPath()}/alice.pem`);
283+
const networkProvider = new ProxyNetworkProvider("https://devnet-gateway.multiversx.com");
284+
285+
const gasLimitEstimator = new GasLimitEstimator({ networkProvider: networkProvider });
286+
const controller = new SmartContractController({
287+
chainID: "D",
288+
networkProvider: networkProvider,
289+
gasLimitEstimator: gasLimitEstimator,
290+
});
291+
292+
const bytecode = await loadContractCode("src/testdata/adder.wasm");
293+
294+
const transaction = await controller.createTransactionForDeploy(alice, 0n, {
295+
bytecode: bytecode,
296+
arguments: [new BigUIntValue(0)],
297+
});
298+
299+
assert.isTrue(transaction.gasLimit > 0n);
300+
});
279301
});
280302
});

src/smartContracts/smartContractController.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ export class SmartContractController extends BaseController {
4848
nonce: bigint,
4949
options: resources.ContractDeployInput & BaseControllerInput,
5050
): Promise<Transaction> {
51-
const transaction = await this.factory.createTransactionForDeploy(sender.address, options);
51+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
5252

53+
const transaction = await this.factory.createTransactionForDeploy(sender.address, options);
5354
await this.setupAndSignTransaction(transaction, options, nonce, sender);
5455

5556
return transaction;
@@ -69,8 +70,9 @@ export class SmartContractController extends BaseController {
6970
nonce: bigint,
7071
options: resources.ContractUpgradeInput & BaseControllerInput,
7172
): Promise<Transaction> {
72-
const transaction = await this.factory.createTransactionForUpgrade(sender.address, options);
73+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
7374

75+
const transaction = await this.factory.createTransactionForUpgrade(sender.address, options);
7476
await this.setupAndSignTransaction(transaction, options, nonce, sender);
7577

7678
return transaction;
@@ -81,8 +83,9 @@ export class SmartContractController extends BaseController {
8183
nonce: bigint,
8284
options: resources.ContractExecuteInput & BaseControllerInput,
8385
): Promise<Transaction> {
84-
const transaction = await this.factory.createTransactionForExecute(sender.address, options);
86+
options.gasLimit = options.gasLimit ? options.gasLimit : 0n;
8587

88+
const transaction = await this.factory.createTransactionForExecute(sender.address, options);
8689
await this.setupAndSignTransaction(transaction, options, nonce, sender);
8790

8891
return transaction;

src/smartContracts/smartContractTransactionsFactory.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe("test smart contract transactions factory", function () {
4040
assert.fail("Expected error was not thrown");
4141
} catch (err) {
4242
assert.instanceOf(err, Err);
43-
assert.match(err.message, /Can't convert args to TypedValues/);
43+
assert.match((err as Error).message, /Can't convert args to TypedValues/);
4444
}
4545
});
4646

@@ -570,7 +570,7 @@ describe("test smart contract transactions factory", function () {
570570
assert.fail("Expected error was not thrown");
571571
} catch (err) {
572572
assert.instanceOf(err, Err);
573-
assert.match(err.message, /Can't convert args to TypedValues/);
573+
assert.match((err as Error).message, /Can't convert args to TypedValues/);
574574
}
575575
});
576576

src/transfers/transferTransactionsFactory.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe("test transfer transactions factory", function () {
2525
assert.fail("Expected error was not thrown");
2626
} catch (err) {
2727
assert.instanceOf(err, ErrBadUsage);
28-
assert.match(err.message, /No token transfer has been provided/);
28+
assert.match((err as Error).message, /No token transfer has been provided/);
2929
}
3030
});
3131

@@ -181,7 +181,7 @@ describe("test transfer transactions factory", function () {
181181

182182
assert.fail("Expected error was not thrown");
183183
} catch (err) {
184-
assert.match(err.message, /Can't set data field when sending esdt tokens/);
184+
assert.match((err as Error).message, /Can't set data field when sending esdt tokens/);
185185
}
186186
});
187187

0 commit comments

Comments
 (0)