Skip to content

Commit

Permalink
test: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency committed Sep 27, 2024
1 parent 7873535 commit e81d8d9
Show file tree
Hide file tree
Showing 14 changed files with 731 additions and 550 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"test": "jest",
"test:watch": "jest --watch",
"test:debug": "node --inspect node_modules/.bin/jest --runInBand",
"starship": "starship --config ./starship/configs/config.local.yaml",
"starship-group": "starship --config ./starship/configs/config.group.local.yaml",
"starship": "starship --config ./starship/configs/config.group.local.yaml",
"starship:test": "jest --config ./jest.starship.config.js --runInBand --verbose --bail",
"starship:debug": "jest --config ./jest.starship.config.js --runInBand --verbose --bail",
"starship:watch": "jest --watch --config ./jest.starship.config.js"
Expand Down
12 changes: 5 additions & 7 deletions src/codegen/cosmos/group/v1/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,13 +552,13 @@ export interface MsgSubmitProposal {
exec: Exec;
/**
* title is the title of the proposal.
*
*
* Since: cosmos-sdk 0.47
*/
title: string;
/**
* summary is the summary of the proposal.
*
*
* Since: cosmos-sdk 0.47
*/
summary: string;
Expand Down Expand Up @@ -591,13 +591,13 @@ export interface MsgSubmitProposalAmino {
exec?: Exec;
/**
* title is the title of the proposal.
*
*
* Since: cosmos-sdk 0.47
*/
title?: string;
/**
* summary is the summary of the proposal.
*
*
* Since: cosmos-sdk 0.47
*/
summary?: string;
Expand Down Expand Up @@ -2834,7 +2834,6 @@ export const MsgSubmitProposal = {
message.exec = object.exec ?? 0;
message.title = object.title ?? "";
message.summary = object.summary ?? "";
console.log('GROUP SUBMIT FROM PARTIAL: ', message.messages);
return message;
},
fromAmino(object: MsgSubmitProposalAmino): MsgSubmitProposal {
Expand Down Expand Up @@ -2875,7 +2874,6 @@ export const MsgSubmitProposal = {
obj.exec = message.exec === 0 ? undefined : message.exec;
obj.title = message.title === "" ? undefined : message.title;
obj.summary = message.summary === "" ? undefined : message.summary;
console.log('GROUP SUBMIT TO AMINO: ', obj.messages);
return obj;
},
fromAminoMsg(object: MsgSubmitProposalAminoMsg): MsgSubmitProposal {
Expand Down Expand Up @@ -3770,4 +3768,4 @@ export const MsgLeaveGroupResponse = {
}
};
GlobalDecoderRegistry.register(MsgLeaveGroupResponse.typeUrl, MsgLeaveGroupResponse);
GlobalDecoderRegistry.registerAminoProtoMapping(MsgLeaveGroupResponse.aminoType, MsgLeaveGroupResponse.typeUrl);
GlobalDecoderRegistry.registerAminoProtoMapping(MsgLeaveGroupResponse.aminoType, MsgLeaveGroupResponse.typeUrl);
25 changes: 13 additions & 12 deletions starship/__tests__/group.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { OfflineSigner } from "@cosmjs/proto-signing";
import {ConfigContext, generateMnemonic, useRegistry} from "starshipjs";
import { ConfigContext, generateMnemonic, useRegistry } from "starshipjs";
import {
checkPoaAdminIs,
createAminoWallet,
createProtoWallet,
initChain, POA_ADDRESS,
poaAdminMnemonic,
initChain,
POA_GROUP_ADDRESS,
// @ts-ignore
} from "../src/test_helper";
import { assertIsDeliverTxSuccess } from "@cosmjs/stargate";
Expand All @@ -21,7 +21,7 @@ import {
import { Duration } from "../../src/codegen/google/protobuf/duration";
import { createRPCQueryClient } from "../../src/codegen/cosmos/rpc.query";
import path from "path";
import {getSigningCosmosTxRpc} from "../../src/codegen";
import { getSigningCosmosTxRpc } from "../../src/codegen";

const inits = [
{
Expand All @@ -34,11 +34,10 @@ const inits = [
},
];

// Test Group module endpoints with both proto and amino signing.
describe.each(inits)("$description", ({ description, createWallets }) => {
let poaWallet: OfflineSigner,
test1Wallet: OfflineSigner,
let test1Wallet: OfflineSigner,
test2Wallet: OfflineSigner,
poaAddress: string,
t1Addr: string,
t2Addr: string,
rpcEndpoint: string,
Expand All @@ -47,25 +46,27 @@ describe.each(inits)("$description", ({ description, createWallets }) => {
const denom = "umfx";

beforeAll(async () => {
const configFile = path.join(__dirname, "..", "configs", "config.local.yaml");
const configFile = path.join(
__dirname,
"..",
"configs",
"config.group.local.yaml"
);
ConfigContext.setConfigFile(configFile);
ConfigContext.setRegistry(await useRegistry(configFile));

const chainData = await initChain("manifest-ledger-beta");
rpcEndpoint = chainData.rpcEndpoint;

await checkPoaAdminIs(rpcEndpoint, POA_ADDRESS);
await checkPoaAdminIs(rpcEndpoint, POA_GROUP_ADDRESS);

poaWallet = await createWallets(poaAdminMnemonic, chainData.prefix);
test1Wallet = await createWallets(generateMnemonic(), chainData.prefix);
test2Wallet = await createWallets(generateMnemonic(), chainData.prefix);
fee = { amount: [{ denom, amount: "100000" }], gas: "550000" };

poaAddress = (await poaWallet.getAccounts())[0].address;
t1Addr = (await test1Wallet.getAccounts())[0].address;
t2Addr = (await test2Wallet.getAccounts())[0].address;

await chainData.creditFromFaucet(poaAddress, denom);
await chainData.creditFromFaucet(t1Addr, denom);
await chainData.creditFromFaucet(t2Addr, denom);
});
Expand Down
145 changes: 145 additions & 0 deletions starship/__tests__/manifest.group.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import {
checkPoaAdminIs,
createAminoWallet,
createProtoWallet,
initChain,
POA_GROUP_ADDRESS,
submitVoteExecGroupProposal,
test1Mnemonic,
test2Mnemonic,
// @ts-ignore
} from "../src/test_helper";
import { OfflineSigner } from "@cosmjs/proto-signing";
import { SigningStargateClient } from "@cosmjs/stargate";
import path from "path";
import { ConfigContext, useRegistry } from "starshipjs";
import { getSigningCosmosClient } from "../../src/codegen";
import { Any } from "../../src/codegen/google/protobuf/any";
import { MessageComposer as ManifestMessageComposer } from "../../src/codegen/liftedinit/manifest/v1/tx.registry";

const inits = [
{
description: "group-manifest-admin (proto-signing)",
createWallets: createProtoWallet,
},
{
description: "group-manifest-admin (amino-signing)",
createWallets: createAminoWallet,
},
];

// Test Manifest module endpoints that require POA Admin permissions with both proto and amino signing.
describe.each(inits)("$description", ({ createWallets }) => {
let test1Wallet: OfflineSigner,
test2Wallet: OfflineSigner,
test1Address: string,
test2Address: string,
rpcEndpoint: string,
fee: { amount: { denom: string; amount: string }[]; gas: string },
cosmosSigningClient: SigningStargateClient;
const denom = "umfx";

beforeAll(async () => {
const configFile = path.join(
__dirname,
"..",
"configs",
"config.group.local.yaml"
);
ConfigContext.setConfigFile(configFile);
ConfigContext.setRegistry(await useRegistry(configFile));

const chainData = await initChain("manifest-ledger-beta");
rpcEndpoint = chainData.rpcEndpoint;

await checkPoaAdminIs(rpcEndpoint, POA_GROUP_ADDRESS);

test1Wallet = await createWallets(test1Mnemonic, chainData.prefix);
test2Wallet = await createWallets(test2Mnemonic, chainData.prefix);
fee = { amount: [{ denom, amount: "100000" }], gas: "550000" };

test1Address = (await test1Wallet.getAccounts())[0].address;
test2Address = (await test2Wallet.getAccounts())[0].address;

expect(test1Address).not.toEqual(test2Address);

await chainData.creditFromFaucet(test1Address, denom);
await chainData.creditFromFaucet(test2Address, denom);

cosmosSigningClient = await getSigningCosmosClient({
rpcEndpoint,
signer: test1Wallet,
});
await cosmosSigningClient.sendTokens(
test1Address,
POA_GROUP_ADDRESS,
[{ denom, amount: "100000000" }],
fee
);
});

test("payout (manifest)", async () => {
const client = await getSigningCosmosClient({
rpcEndpoint,
signer: test1Wallet,
});
const proposal = Any.fromPartial(
ManifestMessageComposer.encoded.payout({
authority: POA_GROUP_ADDRESS,
payoutPairs: [
{
address: test2Address,
coin: { denom, amount: "1000" },
},
],
})
);

const beforeBalance = await client.getBalance(test2Address, denom);
await submitVoteExecGroupProposal(
test1Address,
client,
"payout",
"some payout",
[test1Address],
[proposal],
fee
);

const afterBalance = await client.getBalance(test2Address, denom);
expect(afterBalance.amount).toEqual(
(parseInt(beforeBalance.amount) + 1000).toString()
);
}, 30000);

test("burn (manifest)", async () => {
const proposal = Any.fromPartial(
ManifestMessageComposer.encoded.burnHeldBalance({
authority: POA_GROUP_ADDRESS,
burnCoins: [{ denom, amount: "1000" }],
})
);

const beforeBalance = await cosmosSigningClient.getBalance(
POA_GROUP_ADDRESS,
denom
);
await submitVoteExecGroupProposal(
test1Address,
cosmosSigningClient,
"burn",
"some burn",
[test1Address],
[proposal],
fee
);

const afterBalance = await cosmosSigningClient.getBalance(
POA_GROUP_ADDRESS,
denom
);
expect(afterBalance.amount).toEqual(
(parseInt(beforeBalance.amount) - 1000).toString()
);
}, 30000);
});
Loading

0 comments on commit e81d8d9

Please sign in to comment.