Skip to content

Commit 7d91c05

Browse files
authored
Added additional SDK tests to CI job (#479)
1 parent ee5ca60 commit 7d91c05

File tree

4 files changed

+55
-13
lines changed

4 files changed

+55
-13
lines changed

.github/workflows/sdk.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: TS SDK CI
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
ts-sdk-ci:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: actions/setup-node@v3
16+
with:
17+
node-version: 20
18+
cache: "npm"
19+
registry-url: "https://registry.npmjs.org"
20+
- run: npm ci
21+
- run: npm run build --if-present
22+
- run: npm test

evm/ts/src/ntt.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class EvmNtt<N extends Network, C extends EvmChains>
145145
const payload =
146146
attestation.payloadName === "WormholeTransfer"
147147
? attestation.payload
148-
: attestation.payload.payload;
148+
: attestation.payload["payload"];
149149
const isExecuted = await this.manager.isMessageExecuted(
150150
Ntt.messageDigest(attestation.emitterChain, payload["nttManagerPayload"])
151151
);
@@ -160,7 +160,7 @@ export class EvmNtt<N extends Network, C extends EvmChains>
160160
const payload =
161161
attestation.payloadName === "WormholeTransfer"
162162
? attestation.payload
163-
: attestation.payload.payload;
163+
: attestation.payload["payload"];
164164
return (
165165
(await this.getInboundQueuedTransfer(
166166
attestation.emitterChain,
@@ -173,7 +173,7 @@ export class EvmNtt<N extends Network, C extends EvmChains>
173173
const payload =
174174
attestation.payloadName === "WormholeTransfer"
175175
? attestation.payload
176-
: attestation.payload.payload;
176+
: attestation.payload["payload"];
177177
return this.manager.isMessageApproved(
178178
Ntt.messageDigest(attestation.emitterChain, payload["nttManagerPayload"])
179179
);

sdk/route/__tests__/route.test.ts

+28-8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ const conf: NttRoute.Config = {
4949
};
5050
const network: Network = "Testnet";
5151

52+
const dummyGetProtocol = async function (name: string, params: any) {
53+
if (name !== "Ntt") throw new Error("Unexpected protocol");
54+
return {
55+
getRateLimitDuration: async () => 0n,
56+
getCurrentInboundCapacity: async () => 0n,
57+
};
58+
};
59+
5260
describe("Manual Route Tests", function () {
5361
const wh = new Wormhole("Testnet", [SolanaPlatform, EvmPlatform]);
5462
const fromChain = wh.getChain("Solana");
@@ -88,14 +96,15 @@ describe("Manual Route Tests", function () {
8896
});
8997

9098
let found: routes.ManualRoute<Network>;
99+
let request: routes.RouteTransferRequest<Network>;
91100
it("Should resolve a given route request", async function () {
92-
const request = await routes.RouteTransferRequest.create(wh, {
101+
request = await routes.RouteTransferRequest.create(wh, {
93102
source: Wormhole.tokenId("Solana", SOL_TOKEN),
94103
destination: Wormhole.tokenId("Sepolia", SEPOLIA_TOKEN),
95104
});
96105
const foundRoutes = await resolver.findRoutes(request);
97106
expect(foundRoutes).toHaveLength(1);
98-
expect(foundRoutes[0]!.request.fromChain.chain).toEqual("Solana");
107+
expect(request.fromChain.chain).toEqual("Solana");
99108

100109
const rt = foundRoutes[0]!;
101110
if (!routes.isManual(rt)) throw new Error("Expected manual route");
@@ -111,15 +120,20 @@ describe("Manual Route Tests", function () {
111120

112121
let vp: routes.ValidationResult<typeof op>;
113122
it("Should validate a transfer request", async function () {
114-
vp = await found.validate({ amount: "1.0", options: op });
123+
vp = await found.validate(request, { amount: "1.0", options: op });
115124
expect(vp.valid).toBeTruthy();
116125
expect(vp.params.amount).toEqual("1.0");
117126
});
118127

119128
let qr: Awaited<ReturnType<typeof found.quote>>;
120129
it("Should fetch a quote given the validated parameters", async function () {
121130
if (!vp.valid) throw new Error("Invalid transfer params used");
122-
qr = await found.quote(vp.params);
131+
const getProtocol = request.toChain.getProtocol;
132+
// @ts-ignore
133+
// TODO: mock instead of monkey patch
134+
request.toChain.getProtocol = dummyGetProtocol;
135+
qr = await found.quote(request, vp.params);
136+
request.toChain.getProtocol = getProtocol;
123137
if (!qr.success) throw new Error("Failed to fetch quote");
124138

125139
expect(qr.params.amount).toEqual("1.0");
@@ -179,14 +193,15 @@ describe("Automatic Route Tests", function () {
179193
});
180194

181195
let found: routes.AutomaticRoute<Network>;
196+
let request: routes.RouteTransferRequest<Network>;
182197
it("Should resolve a given route request", async function () {
183-
const request = await routes.RouteTransferRequest.create(wh, {
198+
request = await routes.RouteTransferRequest.create(wh, {
184199
source: Wormhole.tokenId("Solana", SOL_TOKEN),
185200
destination: Wormhole.tokenId("Sepolia", SEPOLIA_TOKEN),
186201
});
187202
const foundRoutes = await resolver.findRoutes(request);
188203
expect(foundRoutes).toHaveLength(1);
189-
expect(foundRoutes[0]!.request.fromChain.chain).toEqual("Solana");
204+
expect(request.fromChain.chain).toEqual("Solana");
190205

191206
const rt = foundRoutes[0]!;
192207
if (!routes.isAutomatic(rt)) throw new Error("Expected automatic route");
@@ -202,15 +217,20 @@ describe("Automatic Route Tests", function () {
202217

203218
let vp: routes.ValidationResult<typeof op>;
204219
it("Should validate a transfer request", async function () {
205-
vp = await found.validate({ amount: "1.0", options: op });
220+
vp = await found.validate(request, { amount: "1.0", options: op });
206221
expect(vp.valid).toBeTruthy();
207222
expect(vp.params.amount).toEqual("1.0");
208223
});
209224

210225
let qr: Awaited<ReturnType<typeof found.quote>>;
211226
it("Should fetch a quote given the validated parameters", async function () {
212227
if (!vp.valid) throw new Error("Invalid transfer params used");
213-
qr = await found.quote(vp.params);
228+
const getProtocol = request.toChain.getProtocol;
229+
// @ts-ignore
230+
// TODO: mock instead of monkey patch
231+
request.toChain.getProtocol = dummyGetProtocol;
232+
qr = await found.quote(request, vp.params);
233+
request.toChain.getProtocol = getProtocol;
214234
if (!qr.success) throw new Error("Failed to fetch quote");
215235

216236
expect(qr.params.amount).toEqual("1.0");

sdk/route/src/automatic.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export class NttAutomaticRoute<N extends Network>
256256
const payload =
257257
vaa.payloadName === "WormholeTransfer"
258258
? vaa.payload
259-
: vaa.payload.payload;
259+
: vaa.payload["payload"];
260260
const completeTransfer = ntt.completeInboundQueuedTransfer(
261261
receipt.from,
262262
payload["nttManagerPayload"],
@@ -331,7 +331,7 @@ export class NttAutomaticRoute<N extends Network>
331331
const payload =
332332
vaa.payloadName === "WormholeTransfer"
333333
? vaa.payload
334-
: vaa.payload.payload;
334+
: vaa.payload["payload"];
335335
const queuedTransfer = await ntt.getInboundQueuedTransfer(
336336
vaa.emitterChain,
337337
payload["nttManagerPayload"]

0 commit comments

Comments
 (0)