Skip to content

Commit

Permalink
upgrade telescope and regen
Browse files Browse the repository at this point in the history
fix e2e tests
  • Loading branch information
Zetazzz committed Dec 18, 2023
1 parent 3b64c9a commit 6818a15
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 143 deletions.
77 changes: 42 additions & 35 deletions examples/telescope-authz/__tests__/gov.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { generateMnemonic } from '@confio/relayer/build/lib/helpers';
import { assertIsDeliverTxSuccess } from '@cosmjs/stargate';
import Long from 'long';
import {
assertIsDeliverTxSuccess,
createProtobufRpcClient,
} from '@cosmjs/stargate';
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
import BigNumber from 'bignumber.js';

import { Tendermint34Client } from '@cosmjs/tendermint-rpc';
import { QueryClient } from '@cosmjs/stargate';

import { cosmos, getSigningOsmosisClient } from '../src/codegen';
import { useChain, waitUntil } from '../src';
import './setup.test';
Expand All @@ -26,15 +31,17 @@ describe('Governance tests for osmosis', () => {
protoSigner = await DirectSecp256k1HdWallet.fromMnemonic(
generateMnemonic(),
{
prefix: chainInfo.chain.bech32_prefix
prefix: chainInfo.chain.bech32_prefix,
}
);
address = (await protoSigner.getAccounts())[0].address;

const tmClient: any = await Tendermint34Client.connect(getRpcEndpoint());
const client = new QueryClient(tmClient);
const rpc = createProtobufRpcClient(client);

// Create custom cosmos interchain client
queryClient = await cosmos.ClientFactory.createRPCQueryClient({
rpcEndpoint: getRpcEndpoint()
});
queryClient = await cosmos.ClientFactory.createRPCQueryClient({ rpc });

// Transfer osmosis to address
await creditFromFaucet(address);
Expand All @@ -43,7 +50,7 @@ describe('Governance tests for osmosis', () => {
it('check address has tokens', async () => {
const { balance } = await queryClient.cosmos.bank.v1beta1.balance({
address,
denom
denom,
});

expect(balance.amount).toEqual('10000000000');
Expand All @@ -53,7 +60,7 @@ describe('Governance tests for osmosis', () => {
const { validators } = await queryClient.cosmos.staking.v1beta1.validators({
status: cosmos.staking.v1beta1.bondStatusToJSON(
cosmos.staking.v1beta1.BondStatus.BOND_STATUS_BONDED
)
),
});
let allValidators = validators;
if (validators.length > 1) {
Expand All @@ -71,12 +78,12 @@ describe('Governance tests for osmosis', () => {
it('stake tokens to genesis validator', async () => {
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
signer: protoSigner
signer: protoSigner,
});

const { balance } = await queryClient.cosmos.bank.v1beta1.balance({
address,
denom
denom,
});

// Stake half of the tokens
Expand All @@ -87,18 +94,18 @@ describe('Governance tests for osmosis', () => {
validatorAddress: validatorAddress,
amount: {
amount: delegationAmount,
denom: balance.denom
}
denom: balance.denom,
},
});

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

const result = await signingClient.signAndBroadcast(address, [msg], fee);
Expand All @@ -108,12 +115,12 @@ describe('Governance tests for osmosis', () => {
it('submit a txt proposal', async () => {
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
signer: protoSigner
signer: protoSigner,
});

const contentMsg = cosmos.gov.v1beta1.TextProposal.fromPartial({
title: 'Test Proposal',
description: 'Test text proposal for the e2e testing'
description: 'Test text proposal for the e2e testing',
});

// Stake half of the tokens
Expand All @@ -122,23 +129,23 @@ describe('Governance tests for osmosis', () => {
initialDeposit: [
{
amount: '1000000',
denom: denom
}
denom: denom,
},
],
content: {
typeUrl: '/cosmos.gov.v1beta1.TextProposal',
value: cosmos.gov.v1beta1.TextProposal.encode(contentMsg).finish()
}
value: cosmos.gov.v1beta1.TextProposal.encode(contentMsg).finish(),
},
});

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

const result = await signingClient.signAndBroadcast(address, [msg], fee);
Expand All @@ -158,7 +165,7 @@ describe('Governance tests for osmosis', () => {

it('query proposal', async () => {
const result = await queryClient.cosmos.gov.v1beta1.proposal({
proposalId: Long.fromString(proposalId)
proposalId: BigInt(proposalId),
});

expect(result.proposal.proposalId.toString()).toEqual(proposalId);
Expand All @@ -168,24 +175,24 @@ describe('Governance tests for osmosis', () => {
// create genesis address signing client
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
signer: protoSigner
signer: protoSigner,
});

// Vote on proposal from genesis mnemonic address
const msg = cosmos.gov.v1beta1.MessageComposer.withTypeUrl.vote({
proposalId: Long.fromString(proposalId),
proposalId: BigInt(proposalId),
voter: address,
option: cosmos.gov.v1beta1.VoteOption.VOTE_OPTION_YES
option: cosmos.gov.v1beta1.VoteOption.VOTE_OPTION_YES,
});

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

const result = await signingClient.signAndBroadcast(address, [msg], fee);
Expand All @@ -194,8 +201,8 @@ describe('Governance tests for osmosis', () => {

it('verify vote', async () => {
const { vote } = await queryClient.cosmos.gov.v1beta1.vote({
proposalId: Long.fromString(proposalId),
voter: address
proposalId: BigInt(proposalId),
voter: address,
});

expect(vote.proposalId.toString()).toEqual(proposalId);
Expand All @@ -206,15 +213,15 @@ describe('Governance tests for osmosis', () => {
it('wait for voting period to end', async () => {
// wait for the voting period to end
const { proposal } = await queryClient.cosmos.gov.v1beta1.proposal({
proposalId: Long.fromString(proposalId)
proposalId: BigInt(proposalId),
});

await expect(waitUntil(proposal.votingEndTime)).resolves.not.toThrow();
}, 200000);

it('verify proposal passed', async () => {
const { proposal } = await queryClient.cosmos.gov.v1beta1.proposal({
proposalId: Long.fromString(proposalId)
proposalId: BigInt(proposalId),
});

expect(proposal.status).toEqual(
Expand Down
38 changes: 24 additions & 14 deletions examples/telescope-authz/__tests__/staking.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { generateMnemonic } from '@confio/relayer/build/lib/helpers';
import { assertIsDeliverTxSuccess } from '@cosmjs/stargate';
import {
assertIsDeliverTxSuccess,
createProtobufRpcClient,
} from '@cosmjs/stargate';
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
import BigNumber from 'bignumber.js';

import { Tendermint34Client } from '@cosmjs/tendermint-rpc';
import { QueryClient } from '@cosmjs/stargate';

import { cosmos, getSigningOsmosisClient } from '../src/codegen';
import { useChain } from '../src';
import './setup.test';
Expand All @@ -22,19 +28,23 @@ describe('Staking tokens testing', () => {
getCoin,
getStargateClient,
getRpcEndpoint,
creditFromFaucet
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;

const tmClient: any = await Tendermint34Client.connect(getRpcEndpoint());
const client = new QueryClient(tmClient);
const rpc = createProtobufRpcClient(client);

// Create custom cosmos interchain client
queryClient = await cosmos.ClientFactory.createRPCQueryClient({
rpcEndpoint: getRpcEndpoint()
rpc,
});

// Transfer osmosis and ibc tokens to address, send only osmo to address
Expand All @@ -44,7 +54,7 @@ describe('Staking tokens testing', () => {
it('check address has tokens', async () => {
const { balance } = await queryClient.cosmos.bank.v1beta1.balance({
address,
denom
denom,
});

expect(balance.amount).toEqual('10000000000');
Expand All @@ -54,7 +64,7 @@ describe('Staking tokens testing', () => {
const { validators } = await queryClient.cosmos.staking.v1beta1.validators({
status: cosmos.staking.v1beta1.bondStatusToJSON(
cosmos.staking.v1beta1.BondStatus.BOND_STATUS_BONDED
)
),
});
let allValidators = validators;
if (validators.length > 1) {
Expand All @@ -72,12 +82,12 @@ describe('Staking tokens testing', () => {
it('stake tokens to genesis validator', async () => {
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
signer: wallet
signer: wallet,
});

const { balance } = await queryClient.cosmos.bank.v1beta1.balance({
address,
denom
denom,
});

// Stake half of the tokens
Expand All @@ -88,18 +98,18 @@ describe('Staking tokens testing', () => {
validatorAddress: validatorAddress,
amount: {
amount: delegationAmount,
denom: balance.denom
}
denom: balance.denom,
},
});

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

const result = await signingClient.signAndBroadcast(address, [msg], fee);
Expand All @@ -110,7 +120,7 @@ describe('Staking tokens testing', () => {
const { delegationResponse } =
await queryClient.cosmos.staking.v1beta1.delegation({
delegatorAddr: address,
validatorAddr: validatorAddress
validatorAddr: validatorAddress,
});

// Assert that the delegation amount is the set delegation amount
Expand Down
Loading

0 comments on commit 6818a15

Please sign in to comment.