Skip to content
Open
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
1 change: 1 addition & 0 deletions docs/api-references/contracts/deploy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Deploy intelligent contracts
| | --appeal-rounds <count> | Override fee profile appeal rounds | No | |
| | --fee-value <wei> | Fee deposit value to send with the transaction | No | |
| | --valid-until <unixTimestamp> | Unix timestamp after which the transaction is invalid | No | |
| | --gas <units> | Outer EVM transaction gas limit; separate from GenLayer fee budgets | No | |
| | --args <args...> | Contract arguments. Supported types: | No | |
| | --wallet <mode> | Signing mode: 'keystore' or 'browser' (sign in MetaMask via a local bridge; forward the port for remote/SSH: ssh -L <port>:127.0.0.1:<port>). Defaults to the 'walletMode' config value, else 'keystore'. | No | |
| -h | --help | display help for command | No | |
1 change: 1 addition & 0 deletions docs/api-references/contracts/write.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Sends a transaction to a contract method that modifies the state
| | --appeal-rounds <count> | Override fee profile appeal rounds | No | |
| | --fee-value <wei> | Fee deposit value to send with the transaction | No | |
| | --valid-until <unixTimestamp> | Unix timestamp after which the transaction is invalid | No | |
| | --gas <units> | Outer EVM transaction gas limit; separate from GenLayer fee budgets | No | |
| | --args <args...> | Contract arguments. Supported types: | No | |
| | --wallet <mode> | Signing mode: 'keystore' or 'browser' (sign in MetaMask via a local bridge; forward the port for remote/SSH: ssh -L <port>:127.0.0.1:<port>). Defaults to the 'walletMode' config value, else 'keystore'. | No | |
| -h | --help | display help for command | No | |
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"eslint-config-prettier": "^10.0.0",
"eslint-import-resolver-typescript": "^4.0.0",
"eslint-plugin-import": "^2.29.1",
"genlayer-js": "github:genlayerlabs/genlayer-js#6f1273885567ff5cda77b7459edfd6666c5859d0",
"genlayer-js": "github:genlayerlabs/genlayer-js#869ef09a0a54c2f47a5ecf59a6caa6c2d0db6208",
"jsdom": "^26.0.0",
"prettier": "^3.2.5",
"release-it": "^19.0.0",
Expand Down
5 changes: 4 additions & 1 deletion src/commands/contracts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import {pathToFileURL} from "url";
import {formatStakingAmount} from "genlayer-js";
import {buildSync} from "esbuild";
import {ContractFeeCliOptions, parseValidUntil, resolveTransactionFees} from "./fees";
import {ContractTransactionCliOptions, parseGas} from "./transaction";
import {assertSuccessfulExecution, transactionConsensusStatus} from "./execution";

export interface DeployOptions extends ContractFeeCliOptions {
export interface DeployOptions extends ContractFeeCliOptions, ContractTransactionCliOptions {
contract?: string;
args?: any[];
rpc?: string;
Expand Down Expand Up @@ -153,13 +154,15 @@ export class DeployAction extends BaseAction {

const leaderOnly = false;
const deployParams: any = {code: contractCode, args: options.args, leaderOnly};
const gas = parseGas(options.gas);
const fees = await resolveTransactionFees(client, options, {
deployTargeted: true,
profileTarget: {kind: "deploy"},
});
const validUntil = parseValidUntil(options);
if (fees) deployParams.fees = fees;
if (validUntil !== undefined) deployParams.validUntil = validUntil;
if (gas !== undefined) deployParams.gas = gas;

this.setSpinnerText("Starting contract deployment...");
if (fees?.feeValue !== undefined) {
Expand Down
8 changes: 8 additions & 0 deletions src/commands/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export function initializeContractsCommands(program: Command) {
.option("--appeal-rounds <count>", "Override fee profile appeal rounds")
.option("--fee-value <wei>", "Fee deposit value to send with the transaction")
.option("--valid-until <unixTimestamp>", "Unix timestamp after which the transaction is invalid")
.option(
"--gas <units>",
"Outer EVM transaction gas limit; separate from GenLayer fee budgets",
)
.option("--args <args...>", ARGS_HELP, parseArg, []),
).action(async (options: DeployOptions) => {
const deployer = new DeployAction();
Expand Down Expand Up @@ -152,6 +156,10 @@ export function initializeContractsCommands(program: Command) {
.option("--appeal-rounds <count>", "Override fee profile appeal rounds")
.option("--fee-value <wei>", "Fee deposit value to send with the transaction")
.option("--valid-until <unixTimestamp>", "Unix timestamp after which the transaction is invalid")
.option(
"--gas <units>",
"Outer EVM transaction gas limit; separate from GenLayer fee budgets",
)
.option("--args <args...>", ARGS_HELP, parseArg, []),
).action(async (contractAddress: string, method: string, options: WriteOptions) => {
const writeAction = new WriteAction();
Expand Down
19 changes: 19 additions & 0 deletions src/commands/contracts/transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export interface ContractTransactionCliOptions {
/** Gas limit for the outer EVM transaction submitted to ConsensusMain. */
gas?: string;
}

export const parseGas = (value: string | undefined): bigint | undefined => {
if (value === undefined) return undefined;

const trimmed = value.trim();
if (!/^(0x[0-9a-fA-F]+|[0-9]+)$/.test(trimmed)) {
throw new Error("--gas must be a positive integer.");
}

const gas = BigInt(trimmed);
if (gas <= 0n) {
throw new Error("--gas must be a positive integer.");
}
return gas;
};
6 changes: 5 additions & 1 deletion src/commands/contracts/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import {formatStakingAmount} from "genlayer-js";
import {BaseAction} from "../../lib/actions/BaseAction";
import {ContractFeeCliOptions, parseValidUntil, resolveTransactionFees} from "./fees";
import {ContractTransactionCliOptions, parseGas} from "./transaction";
import {assertSuccessfulExecution, transactionConsensusStatus} from "./execution";

export interface WriteOptions extends ContractFeeCliOptions {
export interface WriteOptions extends ContractFeeCliOptions, ContractTransactionCliOptions {
args: any[];
rpc?: string;
wallet?: "keystore" | "browser";
Expand All @@ -28,6 +29,7 @@ export class WriteAction extends BaseAction {
appealRounds,
feeValue,
validUntil,
gas,
}: WriteOptions & {
contractAddress: string;
method: string;
Expand All @@ -45,6 +47,7 @@ export class WriteAction extends BaseAction {
args,
value: 0n,
};
const parsedGas = parseGas(gas);
const parsedFees = await resolveTransactionFees(
client,
{fees, feeProfile, feePreset, appealRounds, feeValue, validUntil},
Expand All @@ -60,6 +63,7 @@ export class WriteAction extends BaseAction {
});
if (parsedFees) writeParams.fees = parsedFees;
if (parsedValidUntil !== undefined) writeParams.validUntil = parsedValidUntil;
if (parsedGas !== undefined) writeParams.gas = parsedGas;
if (parsedFees?.feeValue !== undefined) {
const parsedFeeValue = BigInt(parsedFees.feeValue);
this.log(`Fee deposit: ${parsedFeeValue.toString()} wei (~${formatStakingAmount(parsedFeeValue)})`);
Expand Down
22 changes: 22 additions & 0 deletions tests/actions/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,28 @@ describe("DeployAction", () => {
expect(mockClient.deployContract).toHaveReturnedWith(Promise.resolve("mocked_tx_hash"));
});

test("passes an explicit outer EVM gas limit to deployContract", async () => {
vi.mocked(fs.readFileSync).mockReturnValue("contract code");
vi.mocked(mockClient.deployContract).mockResolvedValue("mocked_tx_hash");
vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue({
statusName: "ACCEPTED",
txExecutionResultName: "FINISHED_WITH_RETURN",
data: {contract_address: "0xdasdsadasdasdada"},
});

await deployer.deploy({
contract: "/mocked/contract/path",
gas: "31000000",
});

expect(mockClient.deployContract).toHaveBeenCalledWith({
code: "contract code",
args: undefined,
leaderOnly: false,
gas: 31_000_000n,
});
});

test("deploys contract with fee options", async () => {
const options: DeployOptions = {
contract: "/mocked/contract/path",
Expand Down
23 changes: 23 additions & 0 deletions tests/actions/transaction.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {describe, expect, test} from "vitest";
import {parseGas} from "../../src/commands/contracts/transaction";

describe("parseGas", () => {
test.each([
["32000000", 32_000_000n],
[" 42 ", 42n],
["0x5208", 21_000n],
])("parses %s", (value, expected) => {
expect(parseGas(value)).toBe(expected);
});

test("omits gas when the option is absent", () => {
expect(parseGas(undefined)).toBeUndefined();
});

test.each(["0", "0x0", "-1", "1.5", "32_000_000", "nope"])(
"rejects invalid gas %s",
value => {
expect(() => parseGas(value)).toThrow("--gas must be a positive integer");
},
);
});
22 changes: 22 additions & 0 deletions tests/actions/write.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,28 @@ describe("WriteAction", () => {
});
});

test("passes an explicit outer EVM gas limit to writeContract", async () => {
const mockHash = "0xMockedTransactionHash";
const mockReceipt = {statusName: "ACCEPTED", txExecutionResultName: "FINISHED_WITH_RETURN"};
vi.mocked(mockClient.writeContract).mockResolvedValue(mockHash);
vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue(mockReceipt);

await writeAction.write({
contractAddress: "0xMockedContract",
method: "updateData",
args: [],
gas: "32000000",
});

expect(mockClient.writeContract).toHaveBeenCalledWith({
address: "0xMockedContract",
functionName: "updateData",
args: [],
value: 0n,
gas: 32_000_000n,
});
});

test("calls writeContract with fee options", async () => {
const mockHash = "0xMockedTransactionHash";
const mockReceipt = {statusName: "ACCEPTED", txExecutionResultName: "FINISHED_WITH_RETURN"};
Expand Down
3 changes: 3 additions & 0 deletions tests/commands/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ describe("deploy command", () => {
"4",
"--valid-until",
"999",
"--gas",
"32000000",
]);

expect(DeployAction.prototype.deploy).toHaveBeenCalledWith({
Expand All @@ -74,6 +76,7 @@ describe("deploy command", () => {
fees,
feeValue: "4",
validUntil: "999",
gas: "32000000",
});
});

Expand Down
3 changes: 3 additions & 0 deletions tests/commands/write.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ describe("write command", () => {
"4",
"--valid-until",
"999",
"--gas",
"32000000",
]);

expect(WriteAction.prototype.write).toHaveBeenCalledWith({
Expand All @@ -77,6 +79,7 @@ describe("write command", () => {
fees,
feeValue: "4",
validUntil: "999",
gas: "32000000",
});
});

Expand Down
Loading