Skip to content

Commit

Permalink
fix: dev flows fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-Ixo committed Mar 9, 2023
1 parent 6e503ca commit ef20ebb
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 29 deletions.
4 changes: 3 additions & 1 deletion __tests__/flows/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { WalletUsers } from "../helpers/constants";

export const bankBasic = () =>
describe("Testing the cosmos bank module", () => {
testMsg("/cosmos.bank.v1beta1.MsgSend", () => Cosmos.BankSendTrx());
testMsg("/cosmos.bank.v1beta1.MsgSend", () =>
Cosmos.BankSendTrx(undefined, WalletUsers.tester, WalletUsers.oracle)
);
});

export const authzBasic = () =>
Expand Down
58 changes: 58 additions & 0 deletions __tests__/flows/instantiateProposals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { DeliverTxResponse } from "@cosmjs/stargate";
import { contracts } from "../../src/custom_queries/contract.constants";
import { cosmwasm, testMsg, timeout, utils } from "../helpers/common";
import { WalletUsers } from "../helpers/constants";
import * as Cosmos from "../modules/Cosmos";

export const instantiateModulesProposals = () =>
Expand Down Expand Up @@ -93,3 +96,58 @@ export const instantiateModulesProposals = () =>
expect(true).toBeTruthy();
});
});

// ------------------------------------------------------------
// flow to run after devnet was reset, please dont change
// ------------------------------------------------------------
export const devnetProposals = () =>
describe("Testing the gov module", () => {
const contractPaths = contracts.map((c) => ({
name: c.name,
path: c.path,
}));

testMsg(
"/cosmos.gov.v1beta1.MsgSubmitProposal store wasm contract",
async () => {
const groups = [
contractPaths.slice(0, 4),
contractPaths.slice(4, 8),
contractPaths.slice(8, 12),
contractPaths.slice(12, 16),
contractPaths.slice(16, 20),
contractPaths.slice(20, 24),
contractPaths.slice(24),
];

let i: number;
let j = groups.length;
let res: DeliverTxResponse[];
for (i = 0; i < j; i++) {
console.log(`running group ${i + 1} of ${j}`);
console.log(groups[i]);
res = await Promise.all(
groups[i].map((c, ii) => {
const signer =
ii == 0
? WalletUsers.tester
: ii == 1
? WalletUsers.alice
: ii == 2
? WalletUsers.bob
: WalletUsers.charlie;
return Cosmos.MsgSubmitProposalStoreCW(
c.name,
c.path,
signer,
ii * 0.5
);
})
);
console.log(res!.map((r) => r.rawLog));
}

return res![0];
}
);
});
8 changes: 7 additions & 1 deletion __tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
import { enititiesBasic, supamotoEntities } from "./flows/entities";
import { ibcBasic } from "./flows/ibc";
import { bankBasic, authzBasic, sendTokens } from "./flows/cosmos";
import { instantiateModulesProposals } from "./flows/instantiateProposals";
import {
instantiateModulesProposals,
devnetProposals,
} from "./flows/instantiateProposals";
import { tokenBasic, supamotoTokens } from "./flows/tokens";
import { daoCore, wasmBasic } from "./flows/cosmwasm";
import { quickQueries } from "./flows/quickQueries";
Expand Down Expand Up @@ -49,6 +52,9 @@ generateBlockchainTestUsers();

// Run the below after a devnet reset
// ------------------------------------------
// devnetProposals();
// first run devnetProposals, the run initcontracts.sh on dev server
// immidiately, and wait for all proposals to pass then run below
// registerIidsDev();
// supamotoEntities();
// supamotoTokens();
70 changes: 65 additions & 5 deletions __tests__/modules/Cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
utils,
ixo,
getFileFromPath,
timeout,
} from "../helpers/common";
import Long from "long";

Expand Down Expand Up @@ -44,11 +45,13 @@ export const BankSendTrx = async (
export const MsgSubmitProposalStoreCW = async (
contract: string = "cw721",
pathList?: string[],
signer = WalletUsers.tester,
timeoutSeconds = 0,
instantiateAccessType = cosmwasm.wasm.v1.AccessType.ACCESS_TYPE_EVERYBODY
) => {
const client = await createClient();
const client = await createClient(getUser(signer));

const tester = getUser();
const tester = getUser(signer);
const account = (await tester.getAccounts())[0];
const myAddress = account.address;

Expand All @@ -57,7 +60,7 @@ export const MsgSubmitProposalStoreCW = async (
value: cosmos.gov.v1beta1.MsgSubmitProposal.fromPartial({
initialDeposit: [
cosmos.base.v1beta1.Coin.fromPartial({
amount: "10000000000",
amount: "10000000",
denom: "uixo",
}),
],
Expand Down Expand Up @@ -90,14 +93,71 @@ export const MsgSubmitProposalStoreCW = async (
}),
};

await timeout(timeoutSeconds * 1000);

const response = await client.signAndBroadcast(myAddress, [message], {
amount: [
{
denom: "uixo",
amount: "10000000",
amount: "1000000",
},
],
gas: "10000000",
});
return response;
};

export const MsgSubmitProposalStoreCWMultiple = async (
contracts: { name: string; path: string[] }[],
instantiateAccessType = cosmwasm.wasm.v1.AccessType.ACCESS_TYPE_EVERYBODY
) => {
const client = await createClient();

const tester = getUser();
const account = (await tester.getAccounts())[0];
const myAddress = account.address;

const messages = contracts.map((c) => ({
typeUrl: "/cosmos.gov.v1beta1.MsgSubmitProposal",
value: cosmos.gov.v1beta1.MsgSubmitProposal.fromPartial({
initialDeposit: [
cosmos.base.v1beta1.Coin.fromPartial({
amount: "10000000",
denom: "uixo",
}),
],
proposer: myAddress,
content: {
typeUrl: "/cosmwasm.wasm.v1.StoreCodeProposal",
value: cosmwasm.wasm.v1.StoreCodeProposal.encode(
cosmwasm.wasm.v1.StoreCodeProposal.fromPartial({
title: `Upload ${c.name} smart contract`,
description: "Description",
runAs: myAddress,
wasmByteCode: new Uint8Array(getFileFromPath(c.path, "")),
instantiatePermission: cosmwasm.wasm.v1.AccessConfig.fromPartial({
permission: instantiateAccessType,
addresses:
instantiateAccessType ==
cosmwasm.wasm.v1.AccessType.ACCESS_TYPE_ANY_OF_ADDRESSES
? [myAddress]
: undefined,
}),
unpinCode: false,
})
).finish(),
},
}),
}));

const response = await client.signAndBroadcast(myAddress, messages, {
amount: [
{
denom: "uixo",
amount: (contracts.length * 1000000).toString(),
},
],
gas: "100000000",
gas: (contracts.length * 10000000).toString(),
});
return response;
};
Expand Down
21 changes: 1 addition & 20 deletions __tests__/modules/Queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,6 @@ export const AllBonds = async () => {
return await queryClient.ixo.bonds.v1beta1.bonds({});
};

export const ProjectDoc = async (did: string) => {
return await queryClient.ixo.project.v1.projectDoc({
projectDid: did,
});
};

export const ProjectTx = async (did: string) => {
return await queryClient.ixo.project.v1.projectTx({
projectDid: did,
});
};

export const ProjectAccounts = async (did: string) => {
return await queryClient.ixo.project.v1.projectAccounts({
projectDid: did,
});
};

export const AllEntities = async () => {
return await queryClient.ixo.entity.v1beta1.entityList({});
};
Expand All @@ -32,11 +14,10 @@ export const AllIidDocuments = async () => {

export const IidDocument = async (did: string) => {
return await queryClient.ixo.iid.v1beta1.iidDocument({
id: did
id: did,
});
};

export const AllAccounts = async () => {
return await queryClient.cosmos.auth.v1beta1.accounts({});
};

4 changes: 2 additions & 2 deletions src/custom_queries/contract.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const contracts = [
},
{
name: "dao_pre_propose_approval_single",
path: ['contracts", "daodao", "dao_pre_propose_approval_singl.wasme'],
path: ["contracts", "daodao", "dao_pre_propose_approval_single.wasm"],
category: "daodao",
code: { devnet: 10 },
},
Expand Down Expand Up @@ -109,7 +109,7 @@ export const contracts = [
},
{
name: "cw20_stake_reward_distributor",
path: ['contracts", "daodao", "cw20_stake_reward_distributor.wasm'],
path: ["contracts", "daodao", "cw20_stake_reward_distributor.wasm"],
category: "daodao",
code: { devnet: 19 },
},
Expand Down

0 comments on commit ef20ebb

Please sign in to comment.