Skip to content

Commit

Permalink
Merge pull request #426 from cosmology-tech/anmol/fix-gov-test
Browse files Browse the repository at this point in the history
Fix gov test
  • Loading branch information
Zetazzz committed Aug 24, 2023
2 parents 60b03f0 + ed4b9e7 commit 7bd088d
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ jobs:
with:
values: packages/starship/configs/local-config.yaml
port-forward: true
version: 0.1.34
version: 0.1.38
- name: e2e
run: cd ./packages/starship && yarn run e2e:test
11 changes: 2 additions & 9 deletions packages/starship/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
HELM_NAME = osmojs
HELM_NAME = telescope-starship
HELM_FILE = configs/config.yaml
HELM_REPO = starship
HELM_CHART = devnet
HELM_VERSION = v0.1.34
HELM_VERSION = v0.1.38

###############################################################################
### All commands ###
Expand All @@ -11,9 +11,6 @@ HELM_VERSION = v0.1.34
.PHONY: setup
setup: check setup-helm

.PHONY: start
start: install port-forward

.PHONY: test
test:
yarn run e2e:test
Expand All @@ -40,10 +37,6 @@ install:
@echo "You can check the status with \"kubectl get pods\", run in another terminal please"
helm install -f $(HELM_FILE) $(HELM_NAME) $(HELM_REPO)/$(HELM_CHART) --version $(HELM_VERSION)

.PHONY: upgrade
upgrade:
helm upgrade --debug -f $(HELM_FILE) $(HELM_NAME) $(HELM_REPO)/$(HELM_CHART) --version $(HELM_VERSION)

.PHONY: debug
debug:
helm install --dry-run --debug -f $(HELM_FILE) $(HELM_NAME) $(HELM_REPO)/$(HELM_CHART)
Expand Down
104 changes: 75 additions & 29 deletions packages/starship/__tests__/gov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,32 @@ import { cosmos, getSigningOsmosisClient } from '../src/codegen';
import { useChain, waitUntil } from '../src';
import './setup.test';

xdescribe('Governance tests for osmosis', () => {
let wallet, denom, address;
let chainInfo,
getCoin,
getStargateClient,
getGenesisMnemonic,
getRpcEndpoint,
creditFromFaucet;
describe('Governance tests for osmosis', () => {
let protoSigner, denom, address;
let chainInfo, getCoin, getRpcEndpoint, creditFromFaucet;

// Variables used accross testcases
let queryClient;
let proposalId;
let genesisAddress;
let validatorAddress;

beforeAll(async () => {
({
chainInfo,
getCoin,
getStargateClient,
getGenesisMnemonic,
getRpcEndpoint,
creditFromFaucet
} = useChain('osmosis'));
denom = getCoin().base;

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

// Create custom cosmos interchain client
queryClient = await cosmos.ClientFactory.createRPCQueryClient({
Expand All @@ -56,10 +52,66 @@ xdescribe('Governance tests for osmosis', () => {
expect(balance.amount).toEqual('10000000000');
}, 10000);

it('query validator address', async () => {
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) {
allValidators = validators.sort((a, b) =>
new BigNumber(b.tokens).minus(new BigNumber(a.tokens)).toNumber()
);
}

expect(allValidators.length).toBeGreaterThan(0);

// set validator address to the first one
validatorAddress = allValidators[0].operatorAddress;
});

it('stake tokens to genesis validator', async () => {
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
signer: protoSigner
});

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

// Stake half of the tokens
// eslint-disable-next-line no-undef
const delegationAmount = (BigInt(balance.amount) / BigInt(2)).toString();
const msg = cosmos.staking.v1beta1.MessageComposer.fromPartial.delegate({
delegatorAddress: address,
validatorAddress: validatorAddress,
amount: {
amount: delegationAmount,
denom: balance.denom
}
});

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

const result = await signingClient.signAndBroadcast(address, [msg], fee);
assertIsDeliverTxSuccess(result);
}, 10000);

it('submit a txt proposal', async () => {
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
signer: wallet
signer: protoSigner
});

const contentMsg = cosmos.gov.v1beta1.TextProposal.fromPartial({
Expand Down Expand Up @@ -117,21 +169,15 @@ xdescribe('Governance tests for osmosis', () => {

it('vote on proposal from genesis address', async () => {
// create genesis address signing client
const mnemonic = await getGenesisMnemonic();
const genesisWallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
prefix: chainInfo.chain.bech32_prefix
});
genesisAddress = (await genesisWallet.getAccounts())[0].address;

const genesisSigningClient = await getSigningOsmosisClient({
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
signer: genesisWallet
signer: protoSigner
});

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

Expand All @@ -145,8 +191,8 @@ xdescribe('Governance tests for osmosis', () => {
gas: '550000'
};

const result = await genesisSigningClient.signAndBroadcast(
genesisAddress,
const result = await signingClient.signAndBroadcast(
address,
[msg],
fee
);
Expand All @@ -156,11 +202,11 @@ xdescribe('Governance tests for osmosis', () => {
it('verify vote', async () => {
const { vote } = await queryClient.cosmos.gov.v1beta1.vote({
proposalId: Long.fromString(proposalId),
voter: genesisAddress
voter: address
});

expect(vote.proposalId.toString()).toEqual(proposalId);
expect(vote.voter).toEqual(genesisAddress);
expect(vote.voter).toEqual(address);
expect(vote.option).toEqual(cosmos.gov.v1beta1.VoteOption.VOTE_OPTION_YES);
}, 10000);

Expand Down
63 changes: 14 additions & 49 deletions packages/starship/configs/local-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ chains:
rpc: 26657
faucet: 8007
resources:
limits:
cpu: "0.2"
memory: "200M"
requests:
cpu: "0.2"
memory: "200M"
cpu: "0.2"
memory: "200M"
- name: cosmos-2
type: cosmos
numValidators: 1
Expand All @@ -21,12 +17,8 @@ chains:
rpc: 26653
faucet: 8003
resources:
limits:
cpu: "0.2"
memory: "200M"
requests:
cpu: "0.2"
memory: "200M"
cpu: "0.2"
memory: "200M"

relayers:
- name: osmos-cosmos
Expand All @@ -36,12 +28,8 @@ relayers:
- osmosis-1
- cosmos-2
resources:
limits:
cpu: "0.1"
memory: "100M"
requests:
cpu: "0.1"
memory: "100M"
cpu: "0.1"
memory: "100M"

explorer:
enabled: false
Expand All @@ -52,43 +40,20 @@ registry:
rest: 8081
grpc: 9091
resources:
limits:
cpu: "0.1"
memory: "100M"
requests:
cpu: "0.1"
memory: "100M"
cpu: "0.1"
memory: "100M"

exposer:
resources:
limits:
cpu: "0.1"
memory: "100M"
requests:
cpu: "0.1"
memory: "100M"
cpu: "0.1"
memory: "100M"

faucet:
resources:
limits:
cpu: "0.1"
memory: "100M"
requests:
cpu: "0.1"
memory: "100M"
cpu: "0.1"
memory: "100M"

resources:
node:
limits:
cpu: "0.2"
memory: "200M"
requests:
cpu: "0.2"
memory: "200M"
wait:
limits:
cpu: "0.1"
memory: "100M"
requests:
cpu: "0.1"
memory: "100M"
cpu: "0.1"
memory: "100M"

0 comments on commit 7bd088d

Please sign in to comment.