Skip to content

Commit

Permalink
fix: contract tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
TarekkMA committed Dec 31, 2024
1 parent 71f0618 commit 188676a
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions test/suites/dev/moonbase/test-contract/test-contract-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ import {
describeSuite,
expect,
} from "@moonwall/cli";
import { ALITH_ADDRESS, createEthersTransaction } from "@moonwall/util";
import { encodeFunctionData, type Abi } from "viem";
import { verifyLatestBlockFees } from "../../../../helpers";
import {CHARLETH_PRIVATE_KEY, CHARLETH_ADDRESS, createEthersTransaction} from "@moonwall/util";
import {encodeFunctionData, type Abi} from "viem";
import {verifyLatestBlockFees} from "../../../../helpers";

// TODO: expand these tests to do multiple txn types when added to viem
describeSuite({
id: "D010603",
title: "Contract loop error",
foundationMethods: "dev",
testCases: ({ context, it, log }) => {
testCases: ({context, it, log}) => {
let looperAddress: `0x${string}`;
let looperAbi: Abi;

beforeAll(async () => {
const { contractAddress, abi } = await deployCreateCompiledContract(context, "Looper");
const {
contractAddress,
abi
} = await deployCreateCompiledContract(context, "Looper", {privateKey: CHARLETH_PRIVATE_KEY});

looperAddress = contractAddress;
looperAbi = abi;
Expand All @@ -34,9 +37,9 @@ describeSuite({
expect(
async () =>
await context.viem().call({
account: ALITH_ADDRESS,
account: CHARLETH_ADDRESS,
to: looperAddress,
data: encodeFunctionData({ abi: looperAbi, functionName: "infinite", args: [] }),
data: encodeFunctionData({abi: looperAbi, functionName: "infinite", args: []}),
gas: 12_000_000n,
}),
"Execution succeeded but should have failed"
Expand All @@ -49,15 +52,16 @@ describeSuite({
title: `should fail with OutOfGas on infinite loop ${txnType} transaction`,
test: async function () {
const rawSigned = await createEthersTransaction(context, {
privateKey: CHARLETH_PRIVATE_KEY,
to: looperAddress,
data: encodeFunctionData({ abi: looperAbi, functionName: "infinite", args: [] }),
data: encodeFunctionData({abi: looperAbi, functionName: "infinite", args: []}),
txnType,
});

const { result } = await context.createBlock(rawSigned);
const {result} = await context.createBlock(rawSigned);
const receipt = await context
.viem("public")
.getTransactionReceipt({ hash: result!.hash as `0x${string}` });
.getTransactionReceipt({hash: result!.hash as `0x${string}`});
expect(receipt.status).toBe("reverted");
},
});
Expand All @@ -67,8 +71,9 @@ describeSuite({
title: `should fail with OutOfGas on infinite loop ${txnType} transaction - check fees`,
test: async function () {
const rawSigned = await createEthersTransaction(context, {
privateKey: CHARLETH_PRIVATE_KEY,
to: looperAddress,
data: encodeFunctionData({ abi: looperAbi, functionName: "infinite", args: [] }),
data: encodeFunctionData({abi: looperAbi, functionName: "infinite", args: []}),
txnType,
});

Expand Down

0 comments on commit 188676a

Please sign in to comment.