Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance: Prepare for Monorepo, Remove Ethers, Unskip E2E #113

Merged
merged 3 commits into from
Nov 18, 2024
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
1 change: 0 additions & 1 deletion examples/send-tx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import dotenv from "dotenv";
import { ethers } from "ethers";
import { formatEther, isAddress } from "viem";

import { loadArgs, loadEnv } from "./cli";
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"example": "tsx examples/send-tx.ts",
"lint": "prettier --check '{src,examples,tests}/**/*.{js,jsx,ts,tsx}' && eslint . --ignore-pattern dist/",
"fmt": "prettier --write '{src,examples,tests}/**/*.{js,jsx,ts,tsx}' && yarn lint --fix",
"test": "jest",
"test": "jest --passWithNoTests",
"all": "yarn fmt && yarn lint && yarn build"
},
"dependencies": {
Expand All @@ -59,8 +59,6 @@
"dotenv": "^16.4.5",
"eslint": "^9.14.0",
"eslint-plugin-import": "^2.31.0",
"ethers": "^6.13.4",
"ethers-multisend": "^3.1.0",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"ts-jest": "^29.2.5",
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export * from "./lib/safe-message";
// TODO: Improve re-exports...
export {
Network,
BaseTx,
SignRequestData,
type BaseTx,
type SignRequestData,
populateTx,
NetworkFields,
type NetworkFields,
signatureFromOutcome,
signatureFromTxHash,
requestRouter as mpcRequestRouter,
EthTransactionParams,
type EthTransactionParams,
isRlpHex,
} from "near-ca";
2 changes: 1 addition & 1 deletion src/lib/safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,6 @@ export class SafeContractSuite {
if (ownerIndex === -1) {
throw new Error(`Not a current owner: ${owner}`);
}
return ownerIndex > 0 ? currentOwners[ownerIndex - 1] : SENTINEL_OWNERS;
return ownerIndex > 0 ? currentOwners[ownerIndex - 1]! : SENTINEL_OWNERS;
}
}
4 changes: 3 additions & 1 deletion src/near-safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,9 @@ export class NearSafe {

// Assert uniqueness
assertUnique(fromAddresses);

if (!fromAddresses[0]) {
throw new Error("No from address provided");
}
// Early return with eoaEncoding if `from` is not the Safe
if (!this.encodeForSafe(fromAddresses[0])) {
// TODO: near-ca needs to update this for typed data like we did.
Expand Down
12 changes: 5 additions & 7 deletions tests/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ dotenv.config();

const TESTNET_ROOT_KEY =
"secp256k1:4NfTiv3UsGahebgTaHyD9vF8KYKMBnfd6kh94mK6xv8fGBiJB8TBtFMP5WWXz6B89Ac1fbpzPwAvoyQebemHFwx3";
const MAINNET_ROOT_KEY =
"secp256k1:3tFRbMqmoa6AAALMrEFAYCEoHcqKxeW38YptwowBVBtXK1vo36HDbUWuR6EZmoK4JcH6HDkNMGGqP1ouV7VZUWya";
// const MAINNET_ROOT_KEY =
// "secp256k1:3tFRbMqmoa6AAALMrEFAYCEoHcqKxeW38YptwowBVBtXK1vo36HDbUWuR6EZmoK4JcH6HDkNMGGqP1ouV7VZUWya";

describe("Near Safe Requests", () => {
let adapter: NearSafe;
beforeAll(async () => {
const networkId = "testnet";
// Initialize the NearSafe adapter once before all tests
adapter = await NearSafe.create({
mpc: {
accountId: "neareth-dev.testnet",
mpcContractId: "v1.signer-prod.testnet",
rootPublicKey:
networkId === "testnet" ? TESTNET_ROOT_KEY : MAINNET_ROOT_KEY,
rootPublicKey: TESTNET_ROOT_KEY,
},
pimlicoKey: process.env.PIMLICO_KEY!,
safeSaltNonce: DEFAULT_SAFE_SALT_NONCE,
Expand Down Expand Up @@ -64,7 +62,7 @@ describe("Near Safe Requests", () => {
await expect(adapter.policyForChainId(100)).resolves.not.toThrow();
});

it.only("adapter: encodeEvmTx", async () => {
it("adapter: encodeEvmTx", async () => {
await expect(
adapter.encodeSignRequest({
method: "eth_sendTransaction",
Expand Down Expand Up @@ -125,7 +123,7 @@ describe("Near Safe Requests", () => {
method: "eth_signTypedData_v4",
params: [adapter.mpcAddress, typedDataString],
});
expect(nearPayload.actions[0].params.args).toStrictEqual({
expect(nearPayload.actions[0]!.params.args).toStrictEqual({
request: {
path: "ethereum,1",
payload: [
Expand Down
235 changes: 0 additions & 235 deletions tests/unit/ethers-safe.ts

This file was deleted.

9 changes: 4 additions & 5 deletions tests/unit/lib/multisend.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { decodeMulti as decodeMultiEthers } from "ethers-multisend";
import { encodeFunctionData, erc20Abi, Hex, parseUnits, toHex } from "viem";

import { OperationType } from "../../../src";
Expand Down Expand Up @@ -69,17 +68,17 @@ describe("Multisend", () => {
operation: OperationType.Call,
to: "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
value: toHex(BigInt(parseUnits("10", 18))),
data: "0x00",
data: "0x",
},
{
operation: OperationType.Call,
to: "0x36F4BFC9f49Dc5D4b2d10c4a48a6b30128BD79bC",
value: "0x00",
value: "0x0",
data: ercTransferData,
},
];

const multiSendTx = encodeMulti(input);
const result = decodeMultiEthers(multiSendTx.data);
expect(result).toStrictEqual(input);
expect(decodeMultiViem(multiSendTx.data as Hex)).toStrictEqual(input);
});
});
Loading