genlayer-js 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{.eslintrc.js → .eslintrc.cjs} +1 -0
- package/.github/workflows/test.yml +33 -0
- package/CHANGELOG.md +7 -0
- package/dist/chains/index.cjs +2 -2
- package/dist/chains/index.d.cts +2 -2
- package/dist/chains/index.d.ts +2 -2
- package/dist/chains/index.js +1 -1
- package/dist/{chains-CtZJFz4Q.d.cts → chains-BV4Glo-M.d.cts} +1 -2
- package/dist/{chains-CtZJFz4Q.d.ts → chains-BV4Glo-M.d.ts} +1 -2
- package/dist/{chunk-D7VZGQ4K.js → chunk-3TYB36DW.js} +1 -1
- package/dist/{chunk-BAGFDCQE.cjs → chunk-IINRDYKF.cjs} +1 -1
- package/dist/{clients-DiSeCTYZ.d.cts → clients-B5D5440g.d.cts} +4 -1
- package/dist/{clients-ByaMqS8n.d.ts → clients-CRRMg5Gh.d.ts} +4 -1
- package/dist/{index-vHLY9ggt.d.ts → index-B5TpaPQ6.d.ts} +1 -1
- package/dist/{index-DLN-2YXE.d.cts → index-SfwloK-R.d.cts} +1 -1
- package/dist/index.cjs +6 -6
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +3 -3
- package/src/abi/calldata/encoder.ts +1 -1
- package/src/abi/index.ts +0 -1
- package/src/accounts/IAccountActions.ts +1 -6
- package/src/accounts/actions.ts +1 -6
- package/src/chains/simulator.ts +1 -1
- package/src/transactions/ITransactionActions.ts +1 -6
- package/src/types/chains.ts +1 -1
- package/src/types/clients.ts +1 -0
- package/tests/client.test-d.ts +33 -0
- package/tests/client.test.ts +68 -0
- package/vitest.config.ts +7 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Run Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout code
|
|
17
|
+
uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Setup Node.js
|
|
20
|
+
uses: actions/setup-node@v4
|
|
21
|
+
with:
|
|
22
|
+
node-version: 22
|
|
23
|
+
cache: npm
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: npm ci
|
|
27
|
+
|
|
28
|
+
- name: Run tests
|
|
29
|
+
run: npm test
|
|
30
|
+
timeout-minutes: 5
|
|
31
|
+
|
|
32
|
+
- name: Run linting
|
|
33
|
+
run: npm run lint
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## 0.3.4 (2024-11-14)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* allow accounts to be nullable in `readContract` and add `sim_getTransactionsForAddress` method ([#16](https://github.com/yeagerai/genlayer-js/issues/16)) ([ea4bb6c](https://github.com/yeagerai/genlayer-js/commit/ea4bb6cb53809f6c17a3794ed35aede979bd89e5))
|
|
9
|
+
|
|
3
10
|
## 0.3.3 (2024-11-11)
|
|
4
11
|
|
|
5
12
|
## 0.3.2 (2024-11-06)
|
package/dist/chains/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkIINRDYKFcjs = require('../chunk-IINRDYKF.cjs');
|
|
4
4
|
require('../chunk-75ZPJI57.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
exports.simulator =
|
|
7
|
+
exports.simulator = _chunkIINRDYKFcjs.simulator;
|
package/dist/chains/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { s as simulator } from '../index-
|
|
2
|
-
import '../chains-
|
|
1
|
+
export { s as simulator } from '../index-SfwloK-R.cjs';
|
|
2
|
+
import '../chains-BV4Glo-M.cjs';
|
|
3
3
|
import 'viem';
|
package/dist/chains/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { s as simulator } from '../index-
|
|
2
|
-
import '../chains-
|
|
1
|
+
export { s as simulator } from '../index-B5TpaPQ6.js';
|
|
2
|
+
import '../chains-BV4Glo-M.js';
|
|
3
3
|
import 'viem';
|
package/dist/chains/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client, Transport, PublicActions, Account } from 'viem';
|
|
2
|
-
import { S as SimulatorChain } from './chains-
|
|
2
|
+
import { S as SimulatorChain } from './chains-BV4Glo-M.cjs';
|
|
3
3
|
|
|
4
4
|
type Address$1 = `0x${string}` & {
|
|
5
5
|
length: 42;
|
|
@@ -70,6 +70,9 @@ type GenLayerMethod = {
|
|
|
70
70
|
} | {
|
|
71
71
|
method: "gen_getContractSchemaForCode";
|
|
72
72
|
params: [contractCode: string];
|
|
73
|
+
} | {
|
|
74
|
+
method: "sim_getTransactionsForAddress";
|
|
75
|
+
params: [address: string, filter?: "all" | "from" | "to"];
|
|
73
76
|
} | {
|
|
74
77
|
method: "eth_getTransactionCount";
|
|
75
78
|
params: [address: string];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client, Transport, PublicActions, Account } from 'viem';
|
|
2
|
-
import { S as SimulatorChain } from './chains-
|
|
2
|
+
import { S as SimulatorChain } from './chains-BV4Glo-M.js';
|
|
3
3
|
|
|
4
4
|
type Address$1 = `0x${string}` & {
|
|
5
5
|
length: 42;
|
|
@@ -70,6 +70,9 @@ type GenLayerMethod = {
|
|
|
70
70
|
} | {
|
|
71
71
|
method: "gen_getContractSchemaForCode";
|
|
72
72
|
params: [contractCode: string];
|
|
73
|
+
} | {
|
|
74
|
+
method: "sim_getTransactionsForAddress";
|
|
75
|
+
params: [address: string, filter?: "all" | "from" | "to"];
|
|
73
76
|
} | {
|
|
74
77
|
method: "eth_getTransactionCount";
|
|
75
78
|
params: [address: string];
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkIINRDYKFcjs = require('./chunk-IINRDYKF.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
var _chunkYI62SDKVcjs = require('./chunk-YI62SDKV.cjs');
|
|
@@ -14,7 +14,7 @@ var _viem = require('viem');
|
|
|
14
14
|
function accountActions(client) {
|
|
15
15
|
return {
|
|
16
16
|
fundAccount: async ({ address, amount }) => {
|
|
17
|
-
if (_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]) !==
|
|
17
|
+
if (_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]) !== _chunkIINRDYKFcjs.simulator.id) {
|
|
18
18
|
throw new Error("Client is not connected to the simulator");
|
|
19
19
|
}
|
|
20
20
|
return client.request({
|
|
@@ -102,7 +102,7 @@ function encodeMap(to, arr) {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
encodeNumWithType(to, BigInt(newEntries.length), TYPE_MAP);
|
|
105
|
-
for (const [
|
|
105
|
+
for (const [, k, v] of newEntries) {
|
|
106
106
|
writeNum(to, BigInt(k.length));
|
|
107
107
|
for (const c of k) {
|
|
108
108
|
to.push(c);
|
|
@@ -315,8 +315,8 @@ var transactionActions = (client) => ({
|
|
|
315
315
|
});
|
|
316
316
|
|
|
317
317
|
// src/client/client.ts
|
|
318
|
-
var createClient = (config = { chain:
|
|
319
|
-
const chainConfig = config.chain ||
|
|
318
|
+
var createClient = (config = { chain: _chunkIINRDYKFcjs.simulator }) => {
|
|
319
|
+
const chainConfig = config.chain || _chunkIINRDYKFcjs.simulator;
|
|
320
320
|
const rpcUrl = config.endpoint || chainConfig.rpcUrls.default.http[0];
|
|
321
321
|
const baseClient = _viem.createClient.call(void 0, {
|
|
322
322
|
chain: chainConfig,
|
|
@@ -340,4 +340,4 @@ var createAccount = (accountPrivateKey) => {
|
|
|
340
340
|
|
|
341
341
|
|
|
342
342
|
|
|
343
|
-
exports.chains =
|
|
343
|
+
exports.chains = _chunkIINRDYKFcjs.chains_exports; exports.createAccount = createAccount; exports.createClient = createClient; exports.generatePrivateKey = generatePrivateKey;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { Account } from 'viem';
|
|
3
|
-
import { S as SimulatorChain } from './chains-
|
|
4
|
-
import { G as GenLayerClient } from './clients-
|
|
3
|
+
import { S as SimulatorChain } from './chains-BV4Glo-M.cjs';
|
|
4
|
+
import { G as GenLayerClient } from './clients-B5D5440g.cjs';
|
|
5
5
|
import * as abitype from 'abitype';
|
|
6
6
|
import * as viem__types_experimental_eip7702_types_authorization from 'viem/_types/experimental/eip7702/types/authorization';
|
|
7
7
|
import * as viem_accounts from 'viem/accounts';
|
|
8
|
-
export { i as chains } from './index-
|
|
8
|
+
export { i as chains } from './index-SfwloK-R.cjs';
|
|
9
9
|
|
|
10
10
|
interface ClientConfig {
|
|
11
11
|
chain?: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { Account } from 'viem';
|
|
3
|
-
import { S as SimulatorChain } from './chains-
|
|
4
|
-
import { G as GenLayerClient } from './clients-
|
|
3
|
+
import { S as SimulatorChain } from './chains-BV4Glo-M.js';
|
|
4
|
+
import { G as GenLayerClient } from './clients-CRRMg5Gh.js';
|
|
5
5
|
import * as abitype from 'abitype';
|
|
6
6
|
import * as viem__types_experimental_eip7702_types_authorization from 'viem/_types/experimental/eip7702/types/authorization';
|
|
7
7
|
import * as viem_accounts from 'viem/accounts';
|
|
8
|
-
export { i as chains } from './index-
|
|
8
|
+
export { i as chains } from './index-B5TpaPQ6.js';
|
|
9
9
|
|
|
10
10
|
interface ClientConfig {
|
|
11
11
|
chain?: {
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
chains_exports,
|
|
3
3
|
simulator
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-3TYB36DW.js";
|
|
5
5
|
import {
|
|
6
6
|
Address
|
|
7
7
|
} from "./chunk-M7SA3INM.js";
|
|
@@ -102,7 +102,7 @@ function encodeMap(to, arr) {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
encodeNumWithType(to, BigInt(newEntries.length), TYPE_MAP);
|
|
105
|
-
for (const [
|
|
105
|
+
for (const [, k, v] of newEntries) {
|
|
106
106
|
writeNum(to, BigInt(k.length));
|
|
107
107
|
for (const c of k) {
|
|
108
108
|
to.push(c);
|
package/dist/types/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { A as Address, C as CalldataEncodable, G as GenLayerClient, a as GenLayerMethod, d as GenLayerTransaction, M as MethodDescription, T as TransactionData, e as TransactionDataElement, b as TransactionHash, c as TransactionStatus } from '../clients-
|
|
2
|
-
export { S as SimulatorChain } from '../chains-
|
|
1
|
+
export { A as Address, C as CalldataEncodable, G as GenLayerClient, a as GenLayerMethod, d as GenLayerTransaction, M as MethodDescription, T as TransactionData, e as TransactionDataElement, b as TransactionHash, c as TransactionStatus } from '../clients-B5D5440g.cjs';
|
|
2
|
+
export { S as SimulatorChain } from '../chains-BV4Glo-M.cjs';
|
|
3
3
|
export { Account } from 'viem';
|
|
4
4
|
|
|
5
5
|
type ContractSchema = {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { A as Address, C as CalldataEncodable, G as GenLayerClient, a as GenLayerMethod, d as GenLayerTransaction, M as MethodDescription, T as TransactionData, e as TransactionDataElement, b as TransactionHash, c as TransactionStatus } from '../clients-
|
|
2
|
-
export { S as SimulatorChain } from '../chains-
|
|
1
|
+
export { A as Address, C as CalldataEncodable, G as GenLayerClient, a as GenLayerMethod, d as GenLayerTransaction, M as MethodDescription, T as TransactionData, e as TransactionDataElement, b as TransactionHash, c as TransactionStatus } from '../clients-CRRMg5Gh.js';
|
|
2
|
+
export { S as SimulatorChain } from '../chains-BV4Glo-M.js';
|
|
3
3
|
export { Account } from 'viem';
|
|
4
4
|
|
|
5
5
|
type ContractSchema = {
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "genlayer-js",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.4",
|
|
5
5
|
"description": "GenLayer JavaScript SDK",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsup src/index.ts src/chains/index.ts src/types/index.ts --format cjs,esm --dts --splitting --out-dir dist --no-treeshake",
|
|
10
10
|
"build:watch": "tsup src/index.ts src/chains/index.ts src/types/index.ts --format cjs,esm --dts --splitting --out-dir dist --no-treeshake --watch",
|
|
11
|
-
"test": "vitest",
|
|
11
|
+
"test": "vitest --typecheck",
|
|
12
12
|
"test:watch": "vitest --watch",
|
|
13
|
-
"lint": "eslint . --ext .ts",
|
|
13
|
+
"lint": "eslint . --fix --ext .ts",
|
|
14
14
|
"release": "release-it --ci"
|
|
15
15
|
},
|
|
16
16
|
"exports": {
|
|
@@ -77,7 +77,7 @@ function encodeMap(to: number[], arr: Iterable<[string, CalldataEncodable]>) {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
encodeNumWithType(to, BigInt(newEntries.length), TYPE_MAP);
|
|
80
|
-
for (const [
|
|
80
|
+
for (const [, k, v] of newEntries) {
|
|
81
81
|
writeNum(to, BigInt(k.length));
|
|
82
82
|
for (const c of k) {
|
|
83
83
|
to.push(c);
|
package/src/abi/index.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import {TransactionHash} from "@/types";
|
|
2
|
-
import {Account, Chain, Transport} from "viem";
|
|
3
2
|
|
|
4
|
-
export type IAccountActions
|
|
5
|
-
transport extends Transport = Transport,
|
|
6
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
7
|
-
account extends Account | undefined = Account | undefined,
|
|
8
|
-
> = {
|
|
3
|
+
export type IAccountActions = {
|
|
9
4
|
fundAccount: ({address, amount}: {address: string; amount: number}) => Promise<TransactionHash>;
|
|
10
5
|
};
|
package/src/accounts/actions.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import {GenLayerClient, TransactionHash, SimulatorChain} from "../types";
|
|
2
2
|
import {simulator} from "../chains";
|
|
3
|
-
import {Account, Transport} from "viem";
|
|
4
3
|
|
|
5
|
-
export function accountActions<
|
|
6
|
-
transport extends Transport = Transport,
|
|
7
|
-
chain extends SimulatorChain | undefined = SimulatorChain | undefined,
|
|
8
|
-
account extends Account | undefined = Account | undefined,
|
|
9
|
-
>(client: GenLayerClient<SimulatorChain>) {
|
|
4
|
+
export function accountActions(client: GenLayerClient<SimulatorChain>) {
|
|
10
5
|
return {
|
|
11
6
|
fundAccount: async ({address, amount}: {address: string; amount: number}): Promise<TransactionHash> => {
|
|
12
7
|
if (client.chain?.id !== simulator.id) {
|
package/src/chains/simulator.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import {Account, Chain, Transport} from "viem";
|
|
2
1
|
import {TransactionHash, TransactionStatus, GenLayerTransaction} from "@/types";
|
|
3
2
|
|
|
4
|
-
export type ITransactionActions
|
|
5
|
-
transport extends Transport = Transport,
|
|
6
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
7
|
-
account extends Account | undefined = Account | undefined,
|
|
8
|
-
> = {
|
|
3
|
+
export type ITransactionActions = {
|
|
9
4
|
waitForTransactionReceipt: ({
|
|
10
5
|
hash,
|
|
11
6
|
status,
|
package/src/types/chains.ts
CHANGED
package/src/types/clients.ts
CHANGED
|
@@ -11,6 +11,7 @@ export type GenLayerMethod =
|
|
|
11
11
|
| {method: "eth_sedRawTransaction"; params: [signedTransaction: string]}
|
|
12
12
|
| {method: "gen_getContractSchema"; params: [address: string]}
|
|
13
13
|
| {method: "gen_getContractSchemaForCode"; params: [contractCode: string]}
|
|
14
|
+
| {method: "sim_getTransactionsForAddress"; params: [address: string, filter?: "all" | "from" | "to"]}
|
|
14
15
|
| {method: "eth_getTransactionCount"; params: [address: string]};
|
|
15
16
|
|
|
16
17
|
/*
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {createClient} from "../src/client/client";
|
|
2
|
+
import {simulator} from "../src/chains/simulator";
|
|
3
|
+
import {createAccount, generatePrivateKey} from "../src/accounts/account";
|
|
4
|
+
|
|
5
|
+
test("type checks", () => {
|
|
6
|
+
const client = createClient({
|
|
7
|
+
chain: simulator,
|
|
8
|
+
account: createAccount(generatePrivateKey()),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// This should fail type checking - "whatever" is not a valid filter
|
|
12
|
+
// @ts-expect-error "whatever" is not a valid filter type
|
|
13
|
+
void client.request({
|
|
14
|
+
method: "sim_getTransactionsForAddress",
|
|
15
|
+
params: ["0x1234567890123456789012345678901234567890", "whatever"],
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// This should pass type checking - "all", "to" and "from" are valid filters
|
|
19
|
+
void client.request({
|
|
20
|
+
method: "sim_getTransactionsForAddress",
|
|
21
|
+
params: ["0x1234567890123456789012345678901234567890", "all"],
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
void client.request({
|
|
25
|
+
method: "sim_getTransactionsForAddress",
|
|
26
|
+
params: ["0x1234567890123456789012345678901234567890", "to"],
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
void client.request({
|
|
30
|
+
method: "sim_getTransactionsForAddress",
|
|
31
|
+
params: ["0x1234567890123456789012345678901234567890", "from"],
|
|
32
|
+
});
|
|
33
|
+
});
|
package/tests/client.test.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// tests/client.test.ts
|
|
2
2
|
import {createClient} from "../src/client/client";
|
|
3
3
|
import {simulator} from "../src/chains/simulator";
|
|
4
|
+
import {Address} from "../src/types/accounts";
|
|
5
|
+
import {createAccount, generatePrivateKey} from "../src/accounts/account";
|
|
6
|
+
import {vi} from "vitest";
|
|
4
7
|
|
|
5
8
|
describe("Client Creation", () => {
|
|
6
9
|
it("should create a client for the simulator", () => {
|
|
@@ -9,3 +12,68 @@ describe("Client Creation", () => {
|
|
|
9
12
|
expect(client.chain).toBe(simulator);
|
|
10
13
|
});
|
|
11
14
|
});
|
|
15
|
+
|
|
16
|
+
describe("Client Overrides", () => {
|
|
17
|
+
it("should default to client account if no account is provided", async () => {
|
|
18
|
+
const account = createAccount(generatePrivateKey());
|
|
19
|
+
const client = createClient({
|
|
20
|
+
chain: simulator,
|
|
21
|
+
account,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Mock the client.request method
|
|
25
|
+
vi.spyOn(client, "request").mockResolvedValue(undefined);
|
|
26
|
+
|
|
27
|
+
const contractAddress = "0x1234567890123456789012345678901234567890";
|
|
28
|
+
await client.readContract({
|
|
29
|
+
address: contractAddress as Address,
|
|
30
|
+
functionName: "testFunction",
|
|
31
|
+
args: ["arg1", "arg2"],
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
expect(client.request).toHaveBeenCalledWith({
|
|
35
|
+
method: "eth_call",
|
|
36
|
+
params: [
|
|
37
|
+
{
|
|
38
|
+
to: contractAddress,
|
|
39
|
+
from: account.address,
|
|
40
|
+
data: expect.any(String),
|
|
41
|
+
},
|
|
42
|
+
"latest",
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should override client account if account is provided", async () => {
|
|
48
|
+
const account = createAccount(generatePrivateKey());
|
|
49
|
+
const client = createClient({
|
|
50
|
+
chain: simulator,
|
|
51
|
+
account,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const overrideAccount = createAccount(generatePrivateKey());
|
|
55
|
+
|
|
56
|
+
// Mock the client.request method
|
|
57
|
+
vi.spyOn(client, "request").mockResolvedValue(undefined);
|
|
58
|
+
|
|
59
|
+
const contractAddress = "0x1234567890123456789012345678901234567890";
|
|
60
|
+
await client.readContract({
|
|
61
|
+
account: overrideAccount,
|
|
62
|
+
address: contractAddress as Address,
|
|
63
|
+
functionName: "testFunction",
|
|
64
|
+
args: ["arg1", "arg2"],
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(client.request).toHaveBeenCalledWith({
|
|
68
|
+
method: "eth_call",
|
|
69
|
+
params: [
|
|
70
|
+
{
|
|
71
|
+
to: contractAddress,
|
|
72
|
+
from: overrideAccount.address,
|
|
73
|
+
data: expect.any(String),
|
|
74
|
+
},
|
|
75
|
+
"latest",
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
package/vitest.config.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {defineConfig} from "vitest/config";
|
|
2
|
+
import path from "path";
|
|
2
3
|
|
|
3
4
|
export default defineConfig({
|
|
4
5
|
test: {
|
|
@@ -9,4 +10,9 @@ export default defineConfig({
|
|
|
9
10
|
exclude: ["node_modules/"],
|
|
10
11
|
},
|
|
11
12
|
},
|
|
13
|
+
resolve: {
|
|
14
|
+
alias: {
|
|
15
|
+
"@": path.resolve(__dirname, "./src"),
|
|
16
|
+
},
|
|
17
|
+
},
|
|
12
18
|
});
|