Skip to content

Commit

Permalink
finished token v1 test
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetazzz committed Dec 26, 2023
1 parent b8504cd commit d8a8264
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 46 deletions.
1 change: 1 addition & 0 deletions __fixtures__/v-next/outputinstantrpc/akash/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ export const getSigningAkashTxRpc = async ({
txRpc.signAndBroadcast = (signerAddress: string, messages: EncodeObject[], fee: number | StdFee | "auto", memo?: string) => {
return (signingClient.signAndBroadcast(signerAddress, messages, fee, memo) as Promise<DeliverTxResponse>);
};
return txRpc;
};
1 change: 1 addition & 0 deletions __fixtures__/v-next/outputinstantrpc/cosmos/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ export const getSigningCosmosTxRpc = async ({
txRpc.signAndBroadcast = (signerAddress: string, messages: EncodeObject[], fee: number | StdFee | "auto", memo?: string) => {
return (signingClient.signAndBroadcast(signerAddress, messages, fee, memo) as Promise<DeliverTxResponse>);
};
return txRpc;
};
1 change: 1 addition & 0 deletions __fixtures__/v-next/outputinstantrpc/cosmwasm/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ export const getSigningCosmwasmTxRpc = async ({
txRpc.signAndBroadcast = (signerAddress: string, messages: EncodeObject[], fee: number | StdFee | "auto", memo?: string) => {
return (signingClient.signAndBroadcast(signerAddress, messages, fee, memo) as Promise<DeliverTxResponse>);
};
return txRpc;
};
1 change: 1 addition & 0 deletions __fixtures__/v-next/outputinstantrpc/evmos/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ export const getSigningEvmosTxRpc = async ({
txRpc.signAndBroadcast = (signerAddress: string, messages: EncodeObject[], fee: number | StdFee | "auto", memo?: string) => {
return (signingClient.signAndBroadcast(signerAddress, messages, fee, memo) as Promise<DeliverTxResponse>);
};
return txRpc;
};
1 change: 1 addition & 0 deletions __fixtures__/v-next/outputinstantrpc/ibc/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ export const getSigningIbcTxRpc = async ({
txRpc.signAndBroadcast = (signerAddress: string, messages: EncodeObject[], fee: number | StdFee | "auto", memo?: string) => {
return (signingClient.signAndBroadcast(signerAddress, messages, fee, memo) as Promise<DeliverTxResponse>);
};
return txRpc;
};
1 change: 1 addition & 0 deletions __fixtures__/v-next/outputinstantrpc/osmosis/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ export const getSigningOsmosisTxRpc = async ({
txRpc.signAndBroadcast = (signerAddress: string, messages: EncodeObject[], fee: number | StdFee | "auto", memo?: string) => {
return (signingClient.signAndBroadcast(signerAddress, messages, fee, memo) as Promise<DeliverTxResponse>);
};
return txRpc;
};
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ exports[`createStargateClient w/o defaults 2`] = `
txRpc.signAndBroadcast = (signerAddress: string, messages: EncodeObject[], fee: number | StdFee | "auto", memo?: string) => {
return (signingClient.signAndBroadcast(signerAddress, messages, fee, memo) as Promise<DeliverTxResponse>);
};
return txRpc;
};"
`;

Expand Down
1 change: 1 addition & 0 deletions packages/ast/src/clients/stargate/stargate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ export const createGetTxRpc = (
)
)
),
t.returnStatement(t.identifier("txRpc")),
],
[]
),
Expand Down
121 changes: 77 additions & 44 deletions packages/starship/__tests__/v1/token.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { generateMnemonic } from '@confio/relayer/build/lib/helpers';
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
import { assertIsDeliverTxSuccess } from '@cosmjs/stargate';

import { ibc, getSigningOsmosisClient } from '../../src/codegen1';
import { useChain } from '../../src';
import './setup.test';

describe('Token transfers', () => {
import { generateMnemonic } from "@confio/relayer/build/lib/helpers";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { assertIsDeliverTxSuccess } from "@cosmjs/stargate";

import {
ibc,
getSigningOsmosisClient,
getSigningOsmosisTxRpc,
osmosis,
} from "../../src/codegen1";
import { useChain } from "../../src";
import "./setup.test";
import { MsgSend } from "../../src/codegen1/cosmos/bank/v1beta1/tx";
import { MsgTransfer } from "../../src/codegen1/ibc/applications/transfer/v1/tx";

describe("Token transfers", () => {
let wallet, denom, address;
let chainInfo, getCoin, getStargateClient, getRpcEndpoint, creditFromFaucet;

Expand All @@ -16,20 +23,20 @@ describe('Token transfers', () => {
getCoin,
getStargateClient,
getRpcEndpoint,
creditFromFaucet
} = useChain('osmosis'));
creditFromFaucet,
} = useChain("osmosis"));
denom = getCoin().base;

// Initialize wallet
wallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), {
prefix: chainInfo.chain.bech32_prefix
prefix: chainInfo.chain.bech32_prefix,
});
address = (await wallet.getAccounts())[0].address;

await creditFromFaucet(address);
}, 200000);

it('send osmosis token to address', async () => {
it("send osmosis token to address", async () => {
// Initialize wallet
const wallet2 = await DirectSecp256k1HdWallet.fromMnemonic(
generateMnemonic(),
Expand All @@ -39,50 +46,73 @@ describe('Token transfers', () => {

const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
signer: wallet
signer: wallet,
});

const txRpc = await getSigningOsmosisTxRpc({
rpcEndpoint: getRpcEndpoint(),
signer: wallet,
});

const msgClient = await osmosis.ClientFactory.createRPCMsgClient({
rpc: txRpc,
});

const fee = {
amount: [
{
denom,
amount: '100000'
}
amount: "100000",
},
],
gas: '550000'
gas: "550000",
};

const token = {
amount: '10000000',
denom
amount: "10000000",
denom,
};

// Transfer uosmo tokens from faceut
await signingClient.sendTokens(
const txResult = await msgClient.cosmos.bank.v1beta1.send(
address,
address2,
[token],
MsgSend.fromPartial({
fromAddress: address,
toAddress: address2,
amount: [token],
}),
fee,
'send tokens test'
"send tokens test"
);

assertIsDeliverTxSuccess(txResult);

const balance = await signingClient.getBalance(address2, denom);

expect(balance.amount).toEqual(token.amount);
expect(balance.denom).toEqual(denom);
}, 200000);

it('send ibc osmo tokens to address on cosmos chain', async () => {
it("send ibc osmo tokens to address on cosmos chain", async () => {
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
signer: wallet
signer: wallet,
});

const txRpc = await getSigningOsmosisTxRpc({
rpcEndpoint: getRpcEndpoint(),
signer: wallet,
});

const msgClient = await ibc.ClientFactory.createRPCMsgClient({
rpc: txRpc,
});

const {
chainInfo: cosmosChainInfo,
getStargateClient: cosmosGetStargateClient,
getRpcEndpoint: cosmosRpcEndpoint
} = useChain('cosmos');
getRpcEndpoint: cosmosRpcEndpoint,
} = useChain("cosmos");

// Initialize wallet address for cosmos chain
const cosmosWallet = await DirectSecp256k1HdWallet.fromMnemonic(
Expand Down Expand Up @@ -113,30 +143,33 @@ describe('Token transfers', () => {
amount: [
{
denom,
amount: '100000'
}
amount: "100000",
},
],
gas: '550000'
gas: "550000",
};

const token = {
denom,
amount: '10000000'
amount: "10000000",
};

// send ibc tokens
const resp = await signingClient.sendIbcTokens(
const txResult = await msgClient.ibc.applications.transfer.v1.transfer(
address,
cosmosAddress,
token,
sourcePort,
sourceChannel,
undefined,
timeoutTime,
fee
MsgTransfer.fromPartial({
sourcePort,
sourceChannel,
token,
sender: address,
receiver: cosmosAddress,
timeoutTimestamp: BigInt(timeoutTime),
}),
fee,
"test ibc transfer"
);

assertIsDeliverTxSuccess(resp);
assertIsDeliverTxSuccess(txResult);

// Check osmos in address on cosmos chain
const cosmosClient = await cosmosGetStargateClient();
Expand All @@ -145,17 +178,17 @@ describe('Token transfers', () => {
// check balances
expect(balances.length).toEqual(1);
const ibcBalance = balances.find((balance) => {
return balance.denom.startsWith('ibc/');
return balance.denom.startsWith("ibc/");
});
expect(ibcBalance!.amount).toEqual(token.amount);
expect(ibcBalance!.denom).toContain('ibc/');
expect(ibcBalance!.denom).toContain("ibc/");

// check ibc denom trace of the same
const queryClient = await ibc.ClientFactory.createRPCQueryClient({
rpcEndpoint: cosmosRpcEndpoint()
rpcEndpoint: cosmosRpcEndpoint(),
});
const trace = await queryClient.ibc.applications.transfer.v1.denomTrace({
hash: ibcBalance!.denom.replace('ibc/', '')
hash: ibcBalance!.denom.replace("ibc/", ""),
});
expect(trace?.denomTrace?.baseDenom).toEqual(denom);
}, 200000);
Expand Down
3 changes: 2 additions & 1 deletion packages/starship/scripts/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ telescope({

stargateClients: {
enabled: true,
includeCosmosDefaultTypes: true
includeCosmosDefaultTypes: true,
addGetTxRpc: true
},

aggregatedLCD: {
Expand Down
5 changes: 5 additions & 0 deletions packages/starship/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
export * from './config';
export * from './utils';

//@ts-ignore
export * from './codegen';
//@ts-ignore
export * from './codegen1';
2 changes: 1 addition & 1 deletion packages/telescope/src/generators/create-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const plugin = (
write(builder, 'helpers.ts', builder.options.prototypes.typingsFormat.num64 === 'bigint' ? internalForBigInt : internal);

// should be exported
if (builder.options.includeExternalHelpers || builder.options.reactQuery?.enabled) {
if (builder.options.stargateClients.addGetTxRpc || builder.options.includeExternalHelpers || builder.options.reactQuery?.enabled) {
// also react-query needs these...
builder.files.push('extern.ts');
write(builder, 'extern.ts', builder.options.rpcClients?.useConnectComet ? externalComet : external);
Expand Down

0 comments on commit d8a8264

Please sign in to comment.