-
Notifications
You must be signed in to change notification settings - Fork 270
IP-1286 test(oft-solana): add solana tests #1897
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
base: main
Are you sure you want to change the base?
Changes from all commits
84c4da3
5840ef1
1da29da
937d1eb
368391d
5d6920e
a9a73d8
aa13ba0
d8cae3f
74832cc
6c50bc3
8e7243c
c7f5471
5fa115c
2ae55ab
10995bb
3af6dd1
25c7dc5
b9340cf
da045f3
39e2e94
406b5a7
fb12e7a
a482c21
8415e95
39dadc2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@layerzerolabs/oft-solana-example": patch | ||
| --- | ||
|
|
||
| Add OFT Solana test coverage for peer/config validation and fee withdrawal guards, plus a got shim for test runs. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@layerzerolabs/onft721-zksync-example": patch | ||
| "@layerzerolabs/onft721-example": patch | ||
| --- | ||
|
|
||
| bump solidity version |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ node_modules | |
| coverage | ||
| coverage.json | ||
| target | ||
| test-ledger | ||
| typechain | ||
| typechain-types | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
| "lint:js": "eslint '**/*.{js,ts,json}' && prettier --check .", | ||
| "lint:sol": "solhint 'contracts/**/*.sol'", | ||
| "test": "$npm_execpath run test:forge && $npm_execpath run test:hardhat", | ||
| "test:anchor": "anchor test", | ||
| "test:anchor": "OFT_ID=$(node scripts/resolve-oft-id.js) anchor build --no-idl && $npm_execpath exec ts-mocha -b -p ./tsconfig.json -t 10000000 test/anchor/index.test.ts", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| "test:forge": "forge test", | ||
| "test:hardhat": "hardhat test", | ||
| "test:scripts": "jest --config jest.config.ts --runInBand --testMatch \"**/*.script.test.ts\"" | ||
|
|
@@ -69,6 +69,7 @@ | |
| "@metaplex-foundation/umi-eddsa-web3js": "^0.9.2", | ||
| "@metaplex-foundation/umi-public-keys": "^0.8.9", | ||
| "@metaplex-foundation/umi-web3js-adapters": "^0.9.2", | ||
| "@noble/secp256k1": "^1.7.1", | ||
| "@nomicfoundation/hardhat-ethers": "^3.0.5", | ||
| "@nomiclabs/hardhat-ethers": "^2.2.3", | ||
| "@nomiclabs/hardhat-waffle": "^2.0.6", | ||
|
|
@@ -86,6 +87,7 @@ | |
| "@types/jest": "^29.5.12", | ||
| "@types/mocha": "^10.0.6", | ||
| "@types/node": "~18.18.14", | ||
| "axios": "^1.6.2", | ||
| "bs58": "^6.0.0", | ||
| "chai": "^4.4.1", | ||
| "concurrently": "~9.1.0", | ||
|
|
@@ -105,6 +107,7 @@ | |
| "prettier": "^3.2.5", | ||
| "solhint": "^4.1.1", | ||
| "solidity-bytes-utils": "^0.8.2", | ||
| "ts-mocha": "^10.0.0", | ||
| "ts-node": "^10.9.2", | ||
| "typescript": "^5.4.4" | ||
| }, | ||
|
|
||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #!/usr/bin/env node | ||
| 'use strict'; | ||
|
|
||
| // This script is used specifically in the `test:anchor` npm script to resolve | ||
| // the OFT program ID and output it to stdout. The test/anchor/constants.ts file | ||
| // has its own implementation since it needs the value at TypeScript import time. | ||
|
|
||
| const fs = require('fs'); | ||
|
|
||
| const { Keypair } = require('@solana/web3.js'); | ||
|
|
||
| const keypairPath = 'target/deploy/oft-keypair.json'; | ||
| const fallbackId = '9UovNrJD8pQyBLheeHNayuG1wJSEAoxkmM14vw5gcsTT'; | ||
|
|
||
| function resolveOftId() { | ||
| try { | ||
| if (!fs.existsSync(keypairPath)) { | ||
| const dir = require('path').dirname(keypairPath); | ||
| fs.mkdirSync(dir, { recursive: true }); | ||
| const kp = Keypair.generate(); | ||
| fs.writeFileSync(keypairPath, JSON.stringify(Array.from(kp.secretKey))); | ||
|
||
| return kp.publicKey.toBase58(); | ||
| } | ||
|
|
||
| const secret = JSON.parse(fs.readFileSync(keypairPath, 'utf8')); | ||
| return Keypair.fromSecretKey(Uint8Array.from(secret)).publicKey.toBase58(); | ||
| } catch (error) { | ||
| return fallbackId; | ||
| } | ||
| } | ||
|
|
||
| process.stdout.write(resolveOftId()); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import fs from 'fs' | ||
| import path from 'path' | ||
|
|
||
| import { publicKey } from '@metaplex-foundation/umi' | ||
| import { utils } from '@noble/secp256k1' | ||
| import { Keypair } from '@solana/web3.js' | ||
|
|
||
| import { UMI } from '@layerzerolabs/lz-solana-sdk-v2' | ||
|
|
||
| export const SRC_EID = 50168 | ||
| export const DST_EID = 50125 | ||
| export const INVALID_EID = 999999 // Non-existent EID for testing | ||
| export const TON_EID = 50343 | ||
|
|
||
| const DEFAULT_OFT_KEYPAIR = path.resolve(process.cwd(), 'target/deploy/oft-keypair.json') | ||
| const OFT_PROGRAM_ID_VALUE = | ||
| process.env.OFT_ID ?? readKeypairPublicKey(DEFAULT_OFT_KEYPAIR) ?? '9UovNrJD8pQyBLheeHNayuG1wJSEAoxkmM14vw5gcsTT' | ||
| const ENDPOINT_PROGRAM_ID_VALUE = process.env.LZ_ENDPOINT_PROGRAM_ID ?? '76y77prsiCMvXMjuoZ5VRrhG5qYBrUMYTE5WgHqgjEn6' | ||
| const ULN_PROGRAM_ID_VALUE = process.env.LZ_ULN_PROGRAM_ID ?? '7a4WjyR8VZ7yZz5XJAKm39BUGn5iT9CKcv2pmG9tdXVH' | ||
| const EXECUTOR_PROGRAM_ID_VALUE = process.env.LZ_EXECUTOR_PROGRAM_ID ?? '6doghB248px58JSSwG4qejQ46kFMW4AMj7vzJnWZHNZn' | ||
| const PRICEFEED_PROGRAM_ID_VALUE = process.env.LZ_PRICEFEED_PROGRAM_ID ?? '8ahPGPjEbpgGaZx2NV1iG5Shj7TDwvsjkEDcGWjt94TP' | ||
| const DVN_PROGRAM_IDS_VALUE = (process.env.LZ_DVN_PROGRAM_IDS ?? 'HtEYV4xB4wvsj5fgTkcfuChYpvGYzgzwvNhgDZQNh7wW') | ||
| .split(',') | ||
| .map((value) => value.trim()) | ||
| .filter(Boolean) | ||
|
|
||
| export const OFT_PROGRAM_ID = publicKey(OFT_PROGRAM_ID_VALUE) | ||
|
|
||
| export const DVN_SIGNERS = new Array(4).fill(0).map(() => utils.randomPrivateKey()) | ||
|
|
||
| export const OFT_DECIMALS = 6 | ||
|
|
||
| export const defaultMultiplierBps = 12500 // 125% | ||
|
|
||
| export const endpoint: UMI.EndpointProgram.Endpoint = new UMI.EndpointProgram.Endpoint(ENDPOINT_PROGRAM_ID_VALUE) | ||
| export const uln: UMI.UlnProgram.Uln = new UMI.UlnProgram.Uln(ULN_PROGRAM_ID_VALUE) | ||
| export const executor: UMI.ExecutorProgram.Executor = new UMI.ExecutorProgram.Executor(EXECUTOR_PROGRAM_ID_VALUE) | ||
| export const priceFeed: UMI.PriceFeedProgram.PriceFeed = new UMI.PriceFeedProgram.PriceFeed(PRICEFEED_PROGRAM_ID_VALUE) | ||
|
|
||
| export const dvns = DVN_PROGRAM_IDS_VALUE.map((value) => publicKey(value)) | ||
|
|
||
| function readKeypairPublicKey(keypairPath: string): string | undefined { | ||
| if (!fs.existsSync(keypairPath)) { | ||
| return undefined | ||
| } | ||
|
|
||
| try { | ||
| const secret = JSON.parse(fs.readFileSync(keypairPath, 'utf-8')) as number[] | ||
| const keypair = Keypair.fromSecretKey(Uint8Array.from(secret)) | ||
| return keypair.publicKey.toBase58() | ||
| } catch (error) { | ||
| console.warn(`Failed to read keypair at ${keypairPath}: ${String(error)}`) | ||
| return undefined | ||
| } | ||
| } |


Uh oh!
There was an error while loading. Please reload this page.