Add failing test case for sending tokens

This commit is contained in:
2022-04-21 09:44:24 +05:30
committed by Ashwin Phatak
parent 4dedc3d7c4
commit 6871e35964
8 changed files with 3175 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
import { DirectSecp256k1HdWallet, DirectSecp256k1Wallet } from '@cosmjs/proto-signing';
import { stringToPath } from '@cosmjs/crypto';
import { fromHex } from '@cosmjs/encoding';
import { sendTokens } from './index'
const MNEMONIC = "talent dismiss teach girl mutual arctic burger matrix outdoor rude vapor rose boost drastic glimpse govern illness rhythm avoid fetch derive increase harvest oak";
const PRIVATE_KEY = "1c6dc846552186ef241489c4e4d10b01086d58b8c2ba06de5dfa589bd52cf23e"
describe('Send tokens', () => {
test('Create wallet using mnemonic', async () => {
const path = stringToPath("m/44'/60'/0'/0");
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
MNEMONIC,
{
prefix: 'ethm',
hdPaths: [path]
}
);
await sendTokens(wallet)
});
test('Create wallet using private key', async () => {
const privateKey = fromHex(PRIVATE_KEY);
const wallet = await DirectSecp256k1Wallet.fromKey(privateKey, 'ethm')
await sendTokens(wallet)
});
})
+36
View File
@@ -0,0 +1,36 @@
import { OfflineDirectSigner } from "@cosmjs/proto-signing";
import { assertIsDeliverTxSuccess, SigningStargateClient } from "@cosmjs/stargate";
const RPC_ENDPOINT = "http://127.0.0.1:26657"
export const sendTokens = async (wallet: OfflineDirectSigner) => {
const [firstAccount] = await wallet.getAccounts();
console.log("account", firstAccount)
const client = await SigningStargateClient.connectWithSigner(RPC_ENDPOINT, wallet, { prefix: 'ethm' });
const senderAddress = firstAccount.address
const recipient = "ethm1xv9tklw7d82sezh9haa573wufgy59vmwe6xxe5";
const amount = {
denom: "ethm",
amount: "12345",
};
const sendMsg = {
typeUrl: "/ethm.bank.v1beta1.MsgSend",
value: {
fromAddress: senderAddress,
toAddress: recipient,
amount: [amount],
},
};
const defaultFee = {
amount: [],
gas: "200000",
};
const result = await client.signAndBroadcast(senderAddress, [sendMsg], defaultFee);
assertIsDeliverTxSuccess(result);
}