Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/accountManagement/accountController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class AccountController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -42,6 +43,7 @@ export class AccountController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand Down Expand Up @@ -72,6 +74,7 @@ export class AccountController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand Down
56 changes: 56 additions & 0 deletions src/core/baseController.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { assert } from "chai";
import { Address } from "./address";
import { BaseController } from "./baseController";
import { Transaction } from "./transaction";

class TestableBaseController extends BaseController {
public exposeSetTransactionGasOptions(
transaction: Transaction,
options: { gasLimit?: bigint; gasPrice?: bigint },
): void {
this.setTransactionGasOptions(transaction, options);
}

public exposeSetVersionAndOptionsForGuardian(transaction: Transaction): void {
this.setVersionAndOptionsForGuardian(transaction);
}
}

describe("BaseController Tests", function () {
it("set correct gasLimit", function () {
const controller = new TestableBaseController();

const transaction = new Transaction({
sender: Address.newFromBech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"),
receiver: Address.newFromBech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"),
gasLimit: 0n,
chainID: "D",
});

controller.exposeSetTransactionGasOptions(transaction, { gasLimit: 50000n });
assert.equal(transaction.gasLimit, 50000n);

transaction.guardian = Address.newFromBech32("erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8");
transaction.relayer = Address.newFromBech32("erd1kyaqzaprcdnv4luvanah0gfxzzsnpaygsy6pytrexll2urtd05ts9vegu7");
controller.exposeSetTransactionGasOptions(transaction, {});
assert.equal(transaction.gasLimit, 150000n);
});

it("set correct version and options for guarded transactions", function () {
const controller = new TestableBaseController();

const transaction = new Transaction({
sender: Address.newFromBech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"),
receiver: Address.newFromBech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"),
gasLimit: 0n,
chainID: "D",
version: 0,
options: 0,
guardian: Address.newFromBech32("erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8"),
});

controller.exposeSetVersionAndOptionsForGuardian(transaction);
assert.equal(transaction.version, 2);
assert.equal(transaction.options, 2);
});
});
8 changes: 8 additions & 0 deletions src/core/baseController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Address } from "./address";
import { EXTRA_GAS_LIMIT_FOR_GUARDED_TRANSACTIONS, EXTRA_GAS_LIMIT_FOR_RELAYED_TRANSACTIONS } from "./constants";
import { Transaction } from "./transaction";
import { TransactionComputer } from "./transactionComputer";

export type BaseControllerInput = {
guardian?: Address;
Expand Down Expand Up @@ -30,4 +31,11 @@ export class BaseController {
transaction.gasLimit += BigInt(EXTRA_GAS_LIMIT_FOR_RELAYED_TRANSACTIONS);
}
}

protected setVersionAndOptionsForGuardian(transaction: Transaction): void {
if (transaction.guardian && !transaction.guardian.isEmpty()) {
const txComputer = new TransactionComputer();
txComputer.applyGuardian(transaction, transaction.guardian);
}
}
}
19 changes: 19 additions & 0 deletions src/delegation/delegationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -63,6 +64,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -79,6 +81,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -95,6 +98,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -111,6 +115,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -127,6 +132,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -143,6 +149,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -159,6 +166,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -175,6 +183,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -191,6 +200,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -207,6 +217,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -226,6 +237,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -245,6 +257,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -261,6 +274,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -277,6 +291,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -293,6 +308,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -309,6 +325,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -325,6 +342,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -342,6 +360,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();

this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand Down
3 changes: 3 additions & 0 deletions src/smartContracts/smartContractController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class SmartContractController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -74,6 +75,7 @@ export class SmartContractController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -90,6 +92,7 @@ export class SmartContractController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand Down
Loading
Loading