Skip to content

Commit

Permalink
update fixture files
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin committed Oct 16, 2023
1 parent 91a5233 commit 97502c8
Show file tree
Hide file tree
Showing 38 changed files with 261 additions and 235 deletions.
15 changes: 7 additions & 8 deletions connect/src/protocols/cctpTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
TransferState,
WormholeTransfer,
} from "../wormholeTransfer";
import { retry } from "../tasks";
import { signSendWait } from "../common";
import { DEFAULT_TASK_TIMEOUT } from "../config";

Expand All @@ -45,7 +44,7 @@ export class CCTPTransfer implements WormholeTransfer {
transfer: CCTPTransferDetails;

// Populated after Initialized
txids?: TransactionId[];
txids: TransactionId[] = [];

// Populated if !automatic and after initialized
circleAttestations?: {
Expand Down Expand Up @@ -275,7 +274,7 @@ export class CCTPTransfer implements WormholeTransfer {
this.txids = await signSendWait(fromChain, xfer, signer);
this.state = TransferState.Initiated;

return this.txids!.map(({ txid }) => txid);
return this.txids.map(({ txid }) => txid);
}

private async _fetchWormholeAttestation(
Expand Down Expand Up @@ -306,7 +305,7 @@ export class CCTPTransfer implements WormholeTransfer {
if (!this.circleAttestations || this.circleAttestations.length == 0) {
// If we dont have any circle attestations yet, we need to start by
// fetching the transaction details from the source chain
if (!this.txids)
if (this.txids.length === 0)
throw new Error("No circle attestations or transactions to fetch");

// The last tx should be the circle transfer, its possible there was
Expand All @@ -319,14 +318,14 @@ export class CCTPTransfer implements WormholeTransfer {
this.circleAttestations = [{ id: circleMessage.messageId }];
}

// TODO: add conf for interval per service ?
const retryInterval = 5000;
for (const idx in this.circleAttestations) {
const ca = this.circleAttestations[idx];
if (ca.attestation) continue; // already got it

const task = () => this.wh.getCircleAttestation(ca.id.hash);
const attestation = await retry<string>(task, retryInterval, timeout);
const attestation = await this.wh.getCircleAttestation(
ca.id.hash,
timeout,
);
if (attestation === null)
throw new Error("No attestation available after timeout exhausted");

Expand Down
16 changes: 9 additions & 7 deletions connect/src/protocols/tokenTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export class TokenTransfer implements WormholeTransfer {
// transfer details
transfer: TokenTransferDetails;

// Source txids
txids?: TransactionId[];
// txids, populated once transactions are submitted
txids: TransactionId[] = [];

// The corresponding vaa representing the TokenTransfer
// on the source chain (if its been completed and finalized)
Expand Down Expand Up @@ -132,9 +132,11 @@ export class TokenTransfer implements WormholeTransfer {
!!relayerAddress &&
address.equals(relayerAddress);

const token = vaa.payload.token;

const details: TokenTransferDetails = {
token: { ...vaa.payload.token },
amount: vaa.payload.token.amount,
token: { chain: token.chain, address: token.address },
amount: token.amount,
// TODO: the `from.address` here is a lie, but we don't
// immediately have enough info to get the _correct_ one
from: { chain: id.chain, address: id.emitter },
Expand Down Expand Up @@ -227,8 +229,7 @@ export class TokenTransfer implements WormholeTransfer {
throw new Error("Invalid state transition in `ready`");

if (!this.vaas || this.vaas.length === 0) {
if (!this.txids || this.txids.length === 0)
throw new Error("No txids available");
if (this.txids.length === 0) throw new Error("No txids available");

this.vaas = await Promise.all(
this.txids.map(async (txid: TransactionId) => {
Expand Down Expand Up @@ -269,6 +270,7 @@ export class TokenTransfer implements WormholeTransfer {
if (!this.vaas) throw new Error("No VAA details available");

const toChain = this.wh.getChain(this.transfer.to.chain);

const signerAddress = toNative(signer.chain(), signer.address());

// TODO: when do we get >1?
Expand All @@ -290,7 +292,7 @@ export class TokenTransfer implements WormholeTransfer {
}

const redeemTxids = await signSendWait(toChain, xfer, signer);
this.txids!.push(...redeemTxids);
this.txids.push(...redeemTxids);
return redeemTxids.map(({ txid }) => txid);
}

Expand Down
2 changes: 1 addition & 1 deletion connect/src/whscan-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export async function getVaaBytes(
const { chain, emitter, sequence } = whm;
const chainId = toChainId(chain);
const emitterAddress = stripPrefix(
emitter.toUniversalAddress().toString(),
"0x",
emitter.toUniversalAddress().toString(),
);

const url = `${rpcUrl}/v1/signed_vaa/${chainId}/${emitterAddress}/${sequence}`;
Expand Down
6 changes: 2 additions & 4 deletions connect/src/wormhole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,8 @@ export class Wormhole {
* @throws Errors if context is not found
*/
getChain(chain: ChainName): ChainContext<PlatformName> {
if (!this._chains.has(chain)) {
const platform = this.getPlatform(chain);
this._chains.set(chain, platform.getChain(chain));
}
if (!this._chains.has(chain))
this._chains.set(chain, this.getPlatform(chain).getChain(chain));

return this._chains.get(chain)!;
}
Expand Down
10 changes: 9 additions & 1 deletion examples/src/helpers/signers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
PlatformToChains,
} from "@wormhole-foundation/connect-sdk";
import { ethers } from "ethers";
import { Keypair } from "@solana/web3.js";
import { Keypair, Transaction } from "@solana/web3.js";
import { AccountData } from "@cosmjs/proto-signing";
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
Expand Down Expand Up @@ -91,6 +91,14 @@ export class SolSigner implements Signer {
console.log(`Signing: ${description} for ${this.address()}`);

transaction.partialSign(this._keypair);
(transaction as Transaction).instructions.forEach((ix) => {
console.log(ix.programId.toBase58());
ix.keys.forEach((k) => {
console.log(k.pubkey.toBase58());
});
console.log(ix.data.toString("hex"));
});
// console.log((transaction as Transaction).feePayer?.toBase58());
signed.push(transaction.serialize());
}
return signed;
Expand Down
8 changes: 7 additions & 1 deletion examples/src/tokenBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ import { TransferStuff, getStuff, waitLog } from "./helpers";

const amt = normalizeAmount("0.01", 18n);

const xfer = await TokenTransfer.from(wh, {
chain: "Avalanche",
txid: "0xd3e0c47f8b1be828a5b1eb8a3e48bb4fc583770c698233b0524f041512307094",
});
console.log(xfer);
console.log(await xfer.completeTransfer(destination.signer));
// Choose your adventure
await manualTokenTransfer(wh, "native", amt, source, destination);
//await manualTokenTransfer(wh, "native", amt, source, destination);

// await automaticTokenTransfer(wh, "native", 100_000_000n, source, destination);
// await automaticTokenTransferWithGasDropoff(
Expand Down
10 changes: 3 additions & 7 deletions platforms/cosmwasm/__tests__/unit/platform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ const COSMWASM_CHAINS = chains.filter((c) => c === "Cosmoshub");
describe("Cosmwasm Platform Tests", () => {
describe("Get Chain", () => {
test("No conf", () => {
// no issues just grabbing the chain
const p = CosmwasmPlatform.setConfig(network, {});
expect(p.conf).toEqual({});
const c = p.getChain(COSMWASM_CHAINS[0]);
expect(c).toBeTruthy();
expect(() => p.getChain(COSMWASM_CHAINS[0])).toThrow();
});

test("With conf", () => {
Expand All @@ -41,9 +39,7 @@ describe("Cosmwasm Platform Tests", () => {
// expect getRpc to throw an error since we havent provided
// the conf to figure out how to connect
expect(async () => await p.getRpc(COSMWASM_CHAINS[0])).rejects.toThrow();
expect(
async () => await p.getChain(COSMWASM_CHAINS[0]).getRpc()
).rejects.toThrow();
expect(async () => p.getChain(COSMWASM_CHAINS[0])).rejects.toThrow();
});

test("With conf", async () => {
Expand All @@ -52,7 +48,7 @@ describe("Cosmwasm Platform Tests", () => {
});
expect(async () => await p.getRpc(COSMWASM_CHAINS[0])).not.toThrow();
expect(
async () => await p.getChain(COSMWASM_CHAINS[0]).getRpc()
async () => await p.getChain(COSMWASM_CHAINS[0]).getRpc(),
).not.toThrow();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
},
"rawHeaders": [
"Date",
"Wed, 06 Sep 2023 14:02:28 GMT",
"Mon, 16 Oct 2023 13:45:03 GMT",
"Content-Type",
"application/json",
"Content-Length",
"39",
"Connection",
"close",
"CF-Cache-Status",
"DYNAMIC",
"HIT",
"Access-Control-Allow-Origin",
"*",
"Cache-Control",
Expand All @@ -37,12 +37,14 @@
"86400",
"x-multirpc-response-type",
"1",
"X-Robots-Tag",
"noindex, nofollow",
"Vary",
"Accept-Encoding",
"Server",
"cloudflare",
"CF-RAY",
"80273ff52d350f63-EWR"
"8170bd73a8b442cd-EWR"
],
"responseIsBinary": false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
],
"status": 200,
"response": [
"1f8b0800000000000003000000ffff",
"8aae56ca2acecf2b2a4856b25232d23350d251ca4c51b23231d3512a4a2d2ecd2951b25232a83054aad5c1a1d01445a1018540a93616000000ffff03003a214b0c92000000"
"1f8b0800000000000003000000ffff8aae56ca2acecf2b2a4856b25232d23350d251ca4c51b23231d5512a4a2d2ecd2951b25232a830a01028d5eae0b0c70cc51e43a5da5800000000ffff03003ab5307292000000"
],
"rawHeaders": [
"Date",
"Wed, 06 Sep 2023 14:02:30 GMT",
"Mon, 16 Oct 2023 13:45:06 GMT",
"Content-Type",
"application/json",
"Transfer-Encoding",
Expand All @@ -49,12 +48,14 @@
"86400",
"x-multirpc-response-type",
"1",
"X-Robots-Tag",
"noindex, nofollow",
"Vary",
"Accept-Encoding",
"Server",
"cloudflare",
"CF-RAY",
"80274005edf042d7-EWR",
"8170bd859b9f8c59-EWR",
"Content-Encoding",
"gzip"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"params": [
{
"to": "0x3ee18b2214aff97000d974cf647e7c347e8fa585",
"data": "0x1ff1e286000000000000000000000000000000000000000000000000000000000000000200000000000000000000000020baa02ba4e9665484e80b7f0da2b154b3af3f32"
"data": "0x1ff1e28600000000000000000000000000000000000000000000000000000000000000020000000000000000000000004bc6a1baadb9ab4d56650aefcf00e723b5f69d8a"
},
"latest"
],
Expand All @@ -23,12 +23,11 @@
],
"status": 200,
"response": [
"1f8b0800000000000003000000ffff",
"8aae56ca2acecf2b2a4856b25232d23350d251ca4c51b23231d1512a4a2d2ecd2951b25232a83054aad5c1a1d01845a1018540a93616000000ffff0300ecda684a92000000"
"1f8b08000000000000038aae56ca2acecf2b2a4856b25232d23350d251ca4c51b23231d1512a4a2d2ecd2951b25232a83054aad5c1a1d01845a1018540a93616000000ffff0300ecda684a92000000"
],
"rawHeaders": [
"Date",
"Wed, 06 Sep 2023 14:02:30 GMT",
"Mon, 16 Oct 2023 13:45:06 GMT",
"Content-Type",
"application/json",
"Transfer-Encoding",
Expand All @@ -49,12 +48,14 @@
"86400",
"x-multirpc-response-type",
"1",
"X-Robots-Tag",
"noindex, nofollow",
"Vary",
"Accept-Encoding",
"Server",
"cloudflare",
"CF-RAY",
"80274004e92c43ef-EWR",
"8170bd8458aa41f2-EWR",
"Content-Encoding",
"gzip"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
"status": 200,
"response": [
"1f8b0800000000000003000000ffff",
"8aae56ca2acecf2b2a4856b25232d23350d251ca4c51b23234d0512a4a2d2ecd2951b25232a83054aad5c1a1d088588526442ab44451674021c0ed1e433ad9634c4d7b0c956a6301000000ffff03008d25333eb3010000"
"8aae56ca2acecf2b2a4856b25232d23350d251ca4c51b2b2d4512a4a2d2ecd2951b25232a830a01028d5ea60b7c6d000c51e43dc0a0de9e42023621d644c4d07e1b1c704dd41b100000000ffff030082bb9a1cb3010000"
],
"rawHeaders": [
"Date",
"Wed, 06 Sep 2023 14:02:28 GMT",
"Mon, 16 Oct 2023 13:45:04 GMT",
"Content-Type",
"application/json",
"Transfer-Encoding",
Expand All @@ -81,12 +81,14 @@
"86400",
"x-multirpc-response-type",
"1",
"X-Robots-Tag",
"noindex, nofollow",
"Vary",
"Accept-Encoding",
"Server",
"cloudflare",
"CF-RAY",
"80273ff97c7643f2-EWR",
"8170bd7849fcc359-EWR",
"Content-Encoding",
"gzip"
],
Expand Down Expand Up @@ -132,12 +134,12 @@
],
"status": 200,
"response": [
"1f8b0800000000000003a4cd4b0a84301045d1bdbc7190943155215b1107494cc0a651f10342e3de7bec4010bce303b7fde1b34ee3322778d49586c2d0c3132b2c79ddbf1b3cf44138d50d744fa1bd40fd2ebeffc8a34f345498433089b2386bd814edc4068ad2e45aa2b3a5674e82b3fb030000ffff",
"03001516090123010000"
"1f8b0800000000000003000000ffff",
"a4cd4b0a84301045d1bdbc7190943155215b1107494cc0a651f10342e3de7bec4010bce303b7fde1b34ee3322778d49586c2d0c3132b2c79ddbf1b3cf44138d50d744fa1bd40fd2ebeffc8a34f345498433089b2386bd814edc4068ad2e45aa2b3a5674e82b3fb030000ffff03001516090123010000"
],
"rawHeaders": [
"Date",
"Wed, 06 Sep 2023 14:02:29 GMT",
"Mon, 16 Oct 2023 13:45:04 GMT",
"Content-Type",
"application/json",
"Transfer-Encoding",
Expand All @@ -158,12 +160,14 @@
"86400",
"x-multirpc-response-type",
"1",
"X-Robots-Tag",
"noindex, nofollow",
"Vary",
"Accept-Encoding",
"Server",
"cloudflare",
"CF-RAY",
"80273ffacdcf43a3-EWR",
"8170bd795ed618b4-EWR",
"Content-Encoding",
"gzip"
],
Expand Down
Loading

0 comments on commit 97502c8

Please sign in to comment.