Skip to content

Commit 5980a3c

Browse files
committed
use local anchor network instead of public testnet
1 parent 27e4508 commit 5980a3c

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

solana/tests/anchor.test.ts

+14-17
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ describe("example-native-token-transfers", () => {
122122
let ntt: SolanaNtt<"Devnet", "Solana">;
123123
let signer: Signer;
124124
let sender: AccountAddress<"Solana">;
125+
let tokenAddress: string;
125126

126127
beforeAll(async () => {
127128
try {
@@ -189,15 +190,14 @@ describe("example-native-token-transfers", () => {
189190
TOKEN_PROGRAM
190191
);
191192

193+
tokenAddress = mint.publicKey.toBase58();
192194
// Create our contract client
193195
ntt = new SolanaNtt("Devnet", "Solana", connection, {
194196
...ctx.config.contracts,
195197
ntt: {
196-
token: mint.publicKey.toBase58(),
198+
token: tokenAddress,
197199
manager: NTT_ADDRESS,
198-
transceiver: {
199-
wormhole: NTT_ADDRESS,
200-
},
200+
transceiver: { wormhole: NTT_ADDRESS },
201201
},
202202
});
203203
} catch (e) {
@@ -374,35 +374,32 @@ describe("example-native-token-transfers", () => {
374374
});
375375

376376
describe("Static Checks", () => {
377-
const wh = new Wormhole("Testnet", [SolanaPlatform]);
378-
377+
const wh = new Wormhole("Devnet", [SolanaPlatform]);
378+
const ctx = wh.getChain("Solana");
379379
const overrides = {
380380
Solana: {
381-
token: "EetppHswYvV1jjRWoQKC1hejdeBDHR9NNzNtCyRQfrrQ",
382-
manager: "NTtAaoDJhkeHeaVUHnyhwbPNAN6WgBpHkHBTc6d7vLK",
383-
transceiver: {
384-
wormhole: "ExVbjD8inGXkt7Cx8jVr4GF175sQy1MeqgfaY53Ah8as",
385-
},
381+
token: tokenAddress,
382+
manager: NTT_ADDRESS,
383+
transceiver: { wormhole: NTT_ADDRESS },
386384
},
387385
};
388386

389387
describe("ABI Versions Test", function () {
390-
const ctx = wh.getChain("Solana");
391388
test("It initializes from Rpc", async function () {
392-
const ntt = await SolanaNtt.fromRpc(await ctx.getRpc(), {
389+
const ntt = await SolanaNtt.fromRpc(connection, {
393390
Solana: {
394391
...ctx.config,
395392
contracts: {
396393
...ctx.config.contracts,
397-
...{ ntt: overrides["Solana"] },
394+
ntt: overrides["Solana"],
398395
},
399396
},
400397
});
401398
expect(ntt).toBeTruthy();
402399
});
403400

404401
test("It initializes from constructor", async function () {
405-
const ntt = new SolanaNtt("Testnet", "Solana", await ctx.getRpc(), {
402+
const ntt = new SolanaNtt("Devnet", "Solana", connection, {
406403
...ctx.config.contracts,
407404
...{ ntt: overrides["Solana"] },
408405
});
@@ -411,11 +408,11 @@ describe("example-native-token-transfers", () => {
411408

412409
test("It gets the correct version", async function () {
413410
const version = await SolanaNtt.getVersion(
414-
await ctx.getRpc(),
411+
connection,
415412
{ ntt: overrides["Solana"] },
416413
new SolanaAddress(payer.publicKey.toBase58())
417414
);
418-
expect(version).toBe("1.0.0");
415+
expect(version).toBe("2.0.0");
419416
});
420417
});
421418
});

solana/ts/lib/ntt.ts

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { BN, Program, web3 } from "@coral-xyz/anchor";
1+
import {
2+
BN,
3+
Program,
4+
parseIdlErrors,
5+
translateError,
6+
web3,
7+
} from "@coral-xyz/anchor";
28
import * as splToken from "@solana/spl-token";
39
import {
410
AccountMeta,
@@ -165,19 +171,21 @@ export namespace NTT {
165171
if (!sender) {
166172
const address =
167173
connection.rpcEndpoint === rpc.rpcAddress("Devnet", "Solana")
168-
? "6sbzC1eH4FTujJXWj51eQe25cYvr4xfXbJ1vAj7j2k5J" // The CI pubkey, funded on local network
174+
? "6sbzC1eH4FTujJXWj51eQe25cYvr4xfXbJ1vAj7j2k5J" // The CI pubkey, funded on ci network
175+
: connection.rpcEndpoint.startsWith("http://localhost")
176+
? "98evdAiWr7ey9MAQzoQQMwFQkTsSR6KkWQuFqKrgwNwb" // the anchor pubkey, funded on local network
169177
: "Hk3SdYTJFpawrvRz4qRztuEt2SqoCG7BGj2yJfDJSFbJ"; // The default pubkey is funded on mainnet and devnet we need a funded account to simulate the transaction below
170178
sender = new PublicKey(address);
171179
}
172180

173181
const program = getNttProgram(connection, programId.toString(), "1.0.0");
174182

175183
const ix = await program.methods.version().accountsStrict({}).instruction();
176-
const latestBlockHash =
184+
const { blockhash } =
177185
await program.provider.connection.getLatestBlockhash();
178186
const msg = new TransactionMessage({
179187
payerKey: sender,
180-
recentBlockhash: latestBlockHash.blockhash,
188+
recentBlockhash: blockhash,
181189
instructions: [ix],
182190
}).compileToV0Message();
183191

@@ -187,6 +195,16 @@ export namespace NTT {
187195
tx,
188196
{ sigVerify: false }
189197
);
198+
console.log(txSimulation);
199+
200+
if (!txSimulation.value.returnData || txSimulation.value.err) {
201+
throw new Error(
202+
"Could not fetch IDL version: " +
203+
JSON.stringify(
204+
translateError(txSimulation.value.err, parseIdlErrors(program.idl))
205+
)
206+
);
207+
}
190208

191209
const data = encoding.b64.decode(txSimulation.value.returnData?.data[0]!);
192210
const parsed = deserializeLayout(programVersionLayout, data);

0 commit comments

Comments
 (0)