Skip to content

Commit

Permalink
Merge pull request #62 from ixofoundation/v0.50.8
Browse files Browse the repository at this point in the history
feat: cosmjs v0.32 upgrade and cosmos v0.50 upgrade
  • Loading branch information
Michael-Ixo authored Aug 2, 2024
2 parents aa3503c + cbf7820 commit 5d5a747
Show file tree
Hide file tree
Showing 1,010 changed files with 117,970 additions and 33,879 deletions.
9 changes: 2 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ module.exports = {
'no-await-in-loop': 0,
'no-prototype-builtins': 0,
'no-return-assign': ['error', 'except-parens'],
'no-restricted-syntax': [
2,
'ForInStatement',
'LabeledStatement',
'WithStatement'
],
'no-restricted-syntax': [2, 'ForInStatement', 'LabeledStatement', 'WithStatement'],
'no-unused-vars': [
0,
{
Expand Down Expand Up @@ -64,7 +59,7 @@ module.exports = {
{
trailingComma: 'none',
singleQuote: true,
printWidth: 120
printWidth: 220
}
]
}
Expand Down
8 changes: 5 additions & 3 deletions __tests__/flows/bonds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ export const bondsBasic = () =>

testMsg("/ixo.bonds.v1beta1.MsgCreateBond", () => Bond.CreateBond(false));
testMsg("/ixo.bonds.v1beta1.MsgEditBond", () => Bond.EditBond());
testMsg("/ixo.bonds.v1beta1.MsgBuy", () =>
Bond.Buy(WalletUsers.tester, 1000)
); // Buy 1000 token first to hatch bond
testMsg("/ixo.bonds.v1beta1.MsgBuy", async () => {
const res = await Bond.Buy(WalletUsers.tester, 1000);
// console.dir(res, { depth: null });
return res;
}); // Buy 1000 token first to hatch bond
testMsg("/ixo.bonds.v1beta1.MsgSetNextAlpha", async () => {
console.log(
"waiting 8 seconds to ensure 1 batchBlocks bonds has passed 1 block to change state from HATCH to OPEN"
Expand Down
15 changes: 13 additions & 2 deletions __tests__/flows/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,26 @@ export const bankBasic = () =>
describe("Testing the cosmos bank module", () => {
testMsg("/cosmos.bank.v1beta1.MsgSend", async () => {
const res = await Cosmos.BankSendTrx(
undefined,
100,
WalletUsers.tester,
WalletUsers.alice,
"secp",
"secp"
"ed"
// "ixo1kaluffrp0ncy3dlrerla3nd8v6zxwzmega3v7g"
);
return res;
});
// testMsg("/cosmos.bank.v1beta1.MsgSend", async () => {
// const res = await Cosmos.BankSendTrx(
// 10000,
// WalletUsers.alice,
// WalletUsers.alice,
// "ed",
// "secp"
// // "ixo1kaluffrp0ncy3dlrerla3nd8v6zxwzmega3v7g"
// );
// return res;
// });
});

export const textProposalBasic = () =>
Expand Down
6 changes: 3 additions & 3 deletions __tests__/flows/cosmwasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,11 +740,11 @@ export const swapContract = () => {

const start = Date.now();

const txHashes: BroadcastTxSyncResponse[] = [];
const txHashes: string[] = [];
for (let i = 0; i < txList.length - 1; i++) {
const txRaw: TxRaw = txList[i];
txHashes.push(
await client.tmBroadcastTxSync(TxRaw.encode(txRaw).finish())
await client.broadcastTxSync(TxRaw.encode(txRaw).finish())
);
}
const lastTx: DeliverTxResponse = await client.broadcastTx(
Expand All @@ -755,7 +755,7 @@ export const swapContract = () => {

const swapResponses: DeliverTxResponse[] = [];
for (const hash of txHashes) {
const res = await client.getTx(toHex(hash.hash));
const res = await client.getTx(hash);
swapResponses.push(res as unknown as DeliverTxResponse);
}
swapResponses.push(lastTx);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/flows/iids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export const generateBlockchainTestUsers = () => {
beforeAll(() =>
generateNewWallet(
WalletUsers.tester, // Miguel
"jungle brave person inmate dirt upset try rotate twin fossil grid border"
"urge title veteran subway broccoli print popular cloth win girl search uncover"
// process.env.ROOT_ECS!
)
);
Expand Down
4 changes: 3 additions & 1 deletion __tests__/flows/quickQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { fromTimestamp } from "../../src/codegen/helpers";
import axios from "axios";
import { claims_mainnet, claims_testnet } from "../constants/claims";
import { EcsCredentialsWorkerUrl } from "../setup/constants";
import Long from "long";

export const quickQueries = () =>
describe("Quick queries to see states", () => {
Expand Down Expand Up @@ -258,7 +259,7 @@ export const quickQueries = () =>

// test("Query proposal by id", async () => {
// const res = await queryClient.cosmos.gov.v1beta1.proposal({
// proposalId: Long.fromNumber(69),
// proposalId: Long.fromNumber(12),
// });
// console.log(res.proposal);
// expect(res).toBeTruthy();
Expand All @@ -280,6 +281,7 @@ export const quickQueries = () =>
// .address;
// const res = await queryClient.cosmos.bank.v1beta1.allBalances({
// address,
// resolveDenom: false,
// });
// console.log(res.balances);
// expect(res).toBeTruthy();
Expand Down
14 changes: 11 additions & 3 deletions __tests__/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@ export const generateConstants = (setGlobal = true) => {
return newConstants;
};

export const generateNewConstant = async (constant: keyof typeof constants) => {
/**
* Generates a new constant and logs it to console
* @param constant The constant to generate
* @param fixedConstant If set, the constant will be set to this value
*/
export const generateNewConstant = async (
constant: keyof typeof constants,
fixedConstant?: string
) => {
const newConstants = generateConstants(false);
const newConstant = newConstants[constant];
const newConstant = fixedConstant || newConstants[constant];
// @ts-ignore
constants[constant] = newConstant;
console.log({ constant: newConstant });
return newConstant;
return fixedConstant || newConstant;
};

export const fee: StdFee = {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/helpers/edClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Ed25519, sha256 } from "@cosmjs/crypto";
import { toUtf8, Bech32, toBase64 } from "@cosmjs/encoding";
import { toUtf8, toBase64, toBech32 } from "@cosmjs/encoding";
import { makeSignBytes } from "@cosmjs/proto-signing";
import { decode } from "bs58";
import sovrin from "sovrin-did";
Expand All @@ -18,7 +18,7 @@ export const getEdClient = (mnemonic: string) => {
{
algo: "ed25519-sha-256",
pubkey: Uint8Array.from(decode(didDoc.verifyKey)),
address: Bech32.encode(
address: toBech32(
"ixo",
sha256(decode(didDoc.verifyKey)).slice(0, 20)
),
Expand Down
2 changes: 1 addition & 1 deletion __tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ IID.generateBlockchainTestUsers();

// IID.registerIids();
// Proposals.instantiateModulesProposals();
// Cosmos.bankBasic();
Cosmos.bankBasic();
// IID.iidsBasic();
// Bonds.bondsBasic();
// Entity.enititiesBasic();
Expand Down
23 changes: 13 additions & 10 deletions __tests__/modules/Bond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import base58 from "bs58";
import { createClient, getUser, ixo, cosmos } from "../helpers/common";
import { constants, fee, WalletUsers } from "../helpers/constants";

// set constant for bondDid if have one
const bondDidConst = undefined;

export const CreateBond = async (allowSells: boolean) => {
const client = await createClient();

Expand All @@ -11,7 +14,7 @@ export const CreateBond = async (allowSells: boolean) => {
const did = tester.did + "#" + base58.encode(account.pubkey);

const bond = getUser(WalletUsers.bond);
const bondDid = bond.did;
const bondDid = bondDidConst || bond.did;
const feeReserveAddress = myAddress;

const message = {
Expand Down Expand Up @@ -78,7 +81,7 @@ export const EditBond = async () => {
const did = tester.did + "#" + base58.encode(account.pubkey);

const bond = getUser(WalletUsers.bond);
const bondDid = bond.did;
const bondDid = bondDidConst || bond.did;

const message = {
typeUrl: "/ixo.bonds.v1beta1.MsgEditBond",
Expand Down Expand Up @@ -109,7 +112,7 @@ export const SetNextAlpha = async (alpha: string = "520000000000000000") => {
const did = tester.did + "#" + base58.encode(account.pubkey);

const bond = getUser(WalletUsers.bond);
const bondDid = bond.did;
const bondDid = bondDidConst || bond.did;

const message = {
typeUrl: "/ixo.bonds.v1beta1.MsgSetNextAlpha",
Expand Down Expand Up @@ -140,7 +143,7 @@ export const UpdateBondState = async (
const did = tester.did + "#" + base58.encode(account.pubkey);

const bond = getUser(WalletUsers.bond);
const bondDid = bond.did;
const bondDid = bondDidConst || bond.did;

const message = {
typeUrl: "/ixo.bonds.v1beta1.MsgUpdateBondState",
Expand Down Expand Up @@ -168,7 +171,7 @@ export const Buy = async (
const did = user.did + "#" + base58.encode(account.pubkey);

const bond = getUser(WalletUsers.bond);
const bondDid = bond.did;
const bondDid = bondDidConst || bond.did;

const message = {
typeUrl: "/ixo.bonds.v1beta1.MsgBuy",
Expand Down Expand Up @@ -205,7 +208,7 @@ export const Sell = async (
const did = user.did + "#" + base58.encode(account.pubkey);

const bond = getUser(WalletUsers.bond);
const bondDid = bond.did;
const bondDid = bondDidConst || bond.did;

const message = {
typeUrl: "/ixo.bonds.v1beta1.MsgSell",
Expand Down Expand Up @@ -234,7 +237,7 @@ export const Swap = async () => {
const did = tester.did + "#" + base58.encode(account.pubkey);

const bond = getUser(WalletUsers.bond);
const bondDid = bond.did;
const bondDid = bondDidConst || bond.did;

const message = {
typeUrl: "/ixo.bonds.v1beta1.MsgSwap",
Expand Down Expand Up @@ -263,7 +266,7 @@ export const MakeOutcomePayment = async (amount: number) => {
const did = tester.did + "#" + base58.encode(account.pubkey);

const bond = getUser(WalletUsers.bond);
const bondDid = bond.did;
const bondDid = bondDidConst || bond.did;

const message = {
typeUrl: "/ixo.bonds.v1beta1.MsgMakeOutcomePayment",
Expand All @@ -290,7 +293,7 @@ export const WithdrawShare = async (
const did = user.did + "#" + base58.encode(account.pubkey);

const bond = getUser(WalletUsers.bond);
const bondDid = bond.did;
const bondDid = bondDidConst || bond.did;

const message = {
typeUrl: "/ixo.bonds.v1beta1.MsgWithdrawShare",
Expand All @@ -317,7 +320,7 @@ export const WithdrawReserve = async (
const did = user.did + "#" + base58.encode(account.pubkey);

const bond = getUser(WalletUsers.bond);
const bondDid = bond.did;
const bondDid = bondDidConst || bond.did;

const message = {
typeUrl: "/ixo.bonds.v1beta1.MsgWithdrawReserve",
Expand Down
2 changes: 1 addition & 1 deletion __tests__/modules/CosmWasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const WasmInstantiateTrx = async (
const response = await client.signAndBroadcast(
myAddress,
[message],
getFee(1)
getFee(1, await client.simulate(myAddress, [message], undefined))
);
return response;
};
Expand Down
78 changes: 77 additions & 1 deletion __tests__/modules/Cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const BankSendTrx = async (
return response as any;
};

export const MsgSubmitProposalStoreCW = async (
export const MsgSubmitProposalStoreCWOld = async (
contract: string = "cw721",
pathList?: string[],
signer = WalletUsers.tester,
Expand Down Expand Up @@ -117,6 +117,82 @@ export const MsgSubmitProposalStoreCW = async (
});
return response;
};
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(getUser(signer));

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

const govModAccRes =
await queryClient.cosmos.auth.v1beta1.moduleAccountByName({
name: "gov",
});
if (!govModAccRes?.account?.value)
throw new Error("gov module account not found");
const govModAcc = client.registry.decode(govModAccRes.account)?.baseAccount
?.address;
// console.log({ govModAcc });

const message = {
typeUrl: "/cosmos.gov.v1.MsgSubmitProposal",
value: cosmos.gov.v1.MsgSubmitProposal.fromPartial({
initialDeposit: [
cosmos.base.v1beta1.Coin.fromPartial({
amount: "10000000",
denom: "uixo",
}),
],
proposer: myAddress,
title: `Upload ${contract} smart contract`,
summary: "A cosmwasm smart contract",
expedited: false,
messages: [
{
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode",
value: cosmwasm.wasm.v1.MsgStoreCode.encode(
cosmwasm.wasm.v1.MsgStoreCode.fromPartial({
sender: govModAcc,
wasmByteCode: new Uint8Array(
getFileFromPath(
pathList ?? ["contracts", "ixo", `${contract}.wasm`],
""
)
),
instantiatePermission: cosmwasm.wasm.v1.AccessConfig.fromPartial({
permission: instantiateAccessType,
addresses:
instantiateAccessType ==
cosmwasm.wasm.v1.AccessType.ACCESS_TYPE_ANY_OF_ADDRESSES
? [myAddress]
: undefined,
}),
})
).finish(),
},
],
}),
};

await timeout(timeoutSeconds * 1000);

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

export const MsgSubmitProposalStoreCWMultiple = async (
contracts: { name: string; path: string[] }[],
Expand Down
Loading

0 comments on commit 5d5a747

Please sign in to comment.