Skip to content

Commit

Permalink
feat: new proto files, add token credit transfer, add liquid staking …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
Michael-Ixo committed Nov 28, 2024
1 parent 06545e4 commit c6939f1
Show file tree
Hide file tree
Showing 75 changed files with 1,890 additions and 433 deletions.
20 changes: 19 additions & 1 deletion __tests__/flows/claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ export const claimsBasic = () =>
// ])
// );

// Create relayer node entity first
let relayerNodeEntity = "";
testMsg("/ixo.entity.v1beta1.MsgCreateEntity protocol", async () => {
const res = await Entity.CreateEntity(
"dao",
undefined,
"",
WalletUsers.charlie
);
relayerNodeEntity = utils.common.getValueFromEvents(
res,
"wasm",
"token_id"
);
console.log({ relayerNodeEntity });
return res;
});

// Create protocol
let protocol = "did:ixo:entity:065ba0b99948e2e8ff3228836dee423b";
let adminAccount = "ixo14p4eh3hvunmlvegyysfp5lg8gf6cp6suxxx672";
Expand All @@ -56,7 +74,7 @@ export const claimsBasic = () =>
const res = await Entity.CreateEntity(
"protocol",
undefined,
"",
relayerNodeEntity,
WalletUsers.charlie
);
protocol = utils.common.getValueFromEvents(res, "wasm", "token_id");
Expand Down
31 changes: 12 additions & 19 deletions __tests__/flows/liquidStaking.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
import {
chunkArray,
generateNewWallet,
getFileFromPath,
getUser,
queryClient,
saveFileToPath,
sendFromFaucet,
testMsg,
timeout,
} from "../helpers/common";
import { testMsg, timeout } from "../helpers/common";
import * as Cosmos from "../modules/Cosmos";
import * as LiquidStake from "../modules/LiquidStake";
import { WalletUsers } from "../helpers/constants";
// @ts-ignore
import Long from "long";
import { Grant } from "../../src/codegen/cosmos/feegrant/v1beta1/feegrant";
import { createRegistry, utils } from "../../src";
import { fromTimestamp } from "../../src/codegen/helpers";
import { utils } from "../../src";

export const prepareModuleWithProposals = () =>
describe("Preparing Liquid Stake Module with proposals", () => {
Expand All @@ -40,17 +25,25 @@ export const prepareModuleWithProposals = () =>
async () => {
// wait for proposal to pass
await timeout(1000 * 100);
const res = await LiquidStake.MsgUpdateLiquidStakeWhitelist();
await timeout(1000 * 10);
const res = await LiquidStake.MsgUpdateWhitelistedValidators();
return res;
}
);

// Third update weighted rewards receivers
testMsg("/ixo.liquidstake.v1beta1.MsgUpdateWeightedRewardsReceivers", () =>
LiquidStake.MsgUpdateWeightedRewardsReceivers()
);

testMsg("/ixo.liquidstake.v1beta1.MsgLiquidStake", () =>
LiquidStake.MsgLiquidStake("10000000000")
);

testMsg("/ixo.liquidstake.v1beta1.MsgLiquidUnstake", () =>
LiquidStake.MsgLiquidUnstake("1000000000")
);

testMsg("/cosmos.bank.v1beta1.MsgSend", () =>
LiquidStake.BankSendZeroTrx(1000000000)
);
});
2 changes: 1 addition & 1 deletion __tests__/flows/smartaccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { testMsg } from "../helpers/common";
import * as Smartaccount from "../modules/Smartaccount";

export const smartaccountBasic = () =>
describe("Testing the cosmos bank module", () => {
describe("Testing the ixo smartaccount module", () => {
testMsg("/ixo.smartaccount.v1beta1.MsgAddAuthenticator", async () =>
Smartaccount.MsgAddAuthenticator()
);
Expand Down
9 changes: 9 additions & 0 deletions __tests__/flows/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ export const tokenBasic = () =>
])
);

testMsg("/ixo.token.v1beta1.MsgTransferCredit", () =>
Token.TransferCredit([
{
id: tokenId,
amount: 1,
},
])
);

// testMsg("/ixo.token.v1beta1.MsgPauseToken", () =>
// Token.PauseToken(contractAddress1155, false)
// );
Expand Down
4 changes: 2 additions & 2 deletions __tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ IID.generateBlockchainTestUsers();
// Claims.claimsBasic();
// CosmWasm.daoCore();
// Smartaccount.smartaccountBasic();
// LiquidStake.prepareModuleWithProposals();
// Cosmos.sendTokens();
// IID.iidAddEdKeys();
// Bonds.bondsSellsDisabled();
Expand Down Expand Up @@ -71,8 +72,7 @@ IID.generateBlockchainTestUsers();
// Cosmos.authzBasic();
// Cosmos.textProposalBasic();
// Authz.authzBasic();
// LiquidStake.prepareModuleWithProposals();
CosmWasm.daoCore2();
// CosmWasm.daoCore2();
// Claims.supamotoClaims3();
// Queries.quickQueries();
// web3Storage();
Expand Down
15 changes: 8 additions & 7 deletions __tests__/modules/Cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,18 +488,19 @@ export const MsgSubmitProposalUpdateParams = async () => {
const account = (await tester.getAccounts())[0];
const myAddress = account.address;

// const subspace = "mint";
// const key = "ImpactRewardsReceivers";
const subspace = "mint";
const key = "EpochIdentifier";
const value = JSON.stringify("hour");
// const value = JSON.stringify([
// { address: "ixo1jtlkhddkfvzu4p2vl4dvlszzkqvlthghee44jz", weight: "0.5" },
// { address: "ixo1ruwxxfsp6jgdk88fmyzyp7s3hs20vqmg5f3htp", weight: "0.5" },
// ]);

const subspace = "smartaccount";
// const key = "IsSmartAccountActive";
// const value = JSON.stringify(false);
const key = "CircuitBreakerControllers";
const value = JSON.stringify(["ixo1jtlkhddkfvzu4p2vl4dvlszzkqvlthghee44jz"]);
// const subspace = "smartaccount";
// // const key = "IsSmartAccountActive";
// // const value = JSON.stringify(false);
// const key = "CircuitBreakerControllers";
// const value = JSON.stringify(["ixo1jtlkhddkfvzu4p2vl4dvlszzkqvlthghee44jz"]);

const message = {
typeUrl: "/cosmos.gov.v1beta1.MsgSubmitProposal",
Expand Down
74 changes: 67 additions & 7 deletions __tests__/modules/LiquidStake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
getUser,
cosmos,
queryClient,
cosmwasm,
getFileFromPath,
ixo,
} from "../helpers/common";

Expand Down Expand Up @@ -46,10 +44,11 @@ export const MsgSubmitProposalUpdateLiquidStakeParams = async () => {
ixo.liquidstake.v1beta1.MsgUpdateParams.fromPartial({
authority: govModAcc,
params: ixo.liquidstake.v1beta1.Params.fromPartial({
unstakeFeeRate: "0",
autocompoundFeeRate: "0",
unstakeFeeRate: "100000000000000000",
autocompoundFeeRate: "100000000000000000",
minLiquidStakeAmount: "10000",
feeAccountAddress: myAddress,
feeAccountAddress:
"ixo1w2q3mashs2k4wcpqzs5q5xewnhnnr7wslr34safzvwqzvuqh3gjq7yprry",
whitelistAdminAddress: myAddress,
// unchanged but cant be blank
liquidBondDenom: "uixo",
Expand All @@ -69,7 +68,7 @@ export const MsgSubmitProposalUpdateLiquidStakeParams = async () => {
return response;
};

export const MsgUpdateLiquidStakeWhitelist = async () => {
export const MsgUpdateWhitelistedValidators = async () => {
const client = await createClient();

const tester = getUser();
Expand All @@ -82,7 +81,7 @@ export const MsgUpdateLiquidStakeWhitelist = async () => {
authority: myAddress,
whitelistedValidators: [
{
// addrss of the validator for local chain spinup
// address of the validator for local chain spinup
validatorAddress: "ixovaloper1n8yrmeatsk74dw0zs95ess9sgzptd6thzncf20",
targetWeight: "10000",
},
Expand All @@ -98,6 +97,35 @@ export const MsgUpdateLiquidStakeWhitelist = async () => {
return response;
};

export const MsgUpdateWeightedRewardsReceivers = async () => {
const client = await createClient();

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

const message = {
typeUrl: "/ixo.liquidstake.v1beta1.MsgUpdateWeightedRewardsReceivers",
value:
ixo.liquidstake.v1beta1.MsgUpdateWeightedRewardsReceivers.fromPartial({
authority: myAddress,
weightedRewardsReceivers: [
ixo.liquidstake.v1beta1.WeightedAddress.fromPartial({
address: "ixo1ym5uxusc7z3d93em0hf8dulmrjagg8tghaqhup",
weight: "100000000000000000",
}),
],
}),
};

const response = await client.signAndBroadcast(
myAddress,
[message],
getFee(1, await client.simulate(myAddress, [message], undefined))
);
return response;
};

export const MsgLiquidStake = async (amount = "10000000000") => {
const client = await createClient();

Expand Down Expand Up @@ -149,3 +177,35 @@ export const MsgLiquidUnstake = async (amount = "10000000000") => {
);
return response;
};

export const BankSendZeroTrx = async (
amount = Math.pow(10, 10),
fromUser = WalletUsers.tester,
toUser = WalletUsers.bob
) => {
const client = await createClient(getUser(fromUser));

const fromAddress = (await getUser(fromUser).getAccounts())[0].address;
const toAddress = (await getUser(toUser).getAccounts())[0].address;

const message = {
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: cosmos.bank.v1beta1.MsgSend.fromPartial({
fromAddress,
toAddress,
amount: [
cosmos.base.v1beta1.Coin.fromPartial({
amount: amount.toString(),
denom: "uzero",
}),
],
}),
};

const response = await client.signAndBroadcast(
fromAddress,
[message],
getFee(1, await client.simulate(fromAddress, [message], undefined))
);
return response as any;
};
30 changes: 30 additions & 0 deletions __tests__/modules/Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,36 @@ export const RetireToken = async (
return response;
};

export const TransferCredit = async (
tokens: {
id: string;
amount: number;
}[]
) => {
const client = await createClient();

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

const message = {
typeUrl: "/ixo.token.v1beta1.MsgTransferCredit",
value: ixo.token.v1beta1.MsgTransferCredit.fromPartial({
owner: tester,
reason: "reason",
jurisdiction: "jurisdiction",
tokens: tokens.map((b) =>
ixo.token.v1beta1.TokenBatch.fromPartial({
id: b.id,
amount: b.amount.toString(),
})
),
authorizationId: "authorizationId",
}),
};

const response = await client.signAndBroadcast(tester, [message], fee);
return response;
};

export const PauseToken = async (contractAddress: string, paused: boolean) => {
const client = await createClient();

Expand Down
2 changes: 2 additions & 0 deletions __tests__/setup/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ export const dids = {
ai4gCollection: "",
didOracle: "",
aquaminerCollection: "did:ixo:entity:323dd1f9999c20142789010dae287a65",
fairClimateCollection: "",
};

export const adminEntityAccounts = {
assetCollection: "ixo19e74tjy6gdwt0hjj6ph6xgtjhuulgqkzk8xaj4",
legacyCollection: "ixo1kaluffrp0ncy3dlrerla3nd8v6zxwzmega3v7g",
ai4gCollection: "",
fairClimateCollection: "",
};

// export const EcsCredentialsWorkerUrl = "http://localhost:3000/";
Expand Down
10 changes: 5 additions & 5 deletions proto/ixo/bonds/v1beta1/bonds.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/ixofoundation/ixo-blockchain/v3/x/bonds/types";
option go_package = "github.com/ixofoundation/ixo-blockchain/v4/x/bonds/types";

// FunctionParam is a key-value pair used for specifying a specific bond
// parameter.
Expand Down Expand Up @@ -39,11 +39,11 @@ message Bond {
string description = 3;
string creator_did = 4 [
(gogoproto.casttype) =
"github.com/ixofoundation/ixo-blockchain/v3/x/iid/types.DIDFragment"
"github.com/ixofoundation/ixo-blockchain/v4/x/iid/types.DIDFragment"
];
string controller_did = 5 [
(gogoproto.casttype) =
"github.com/ixofoundation/ixo-blockchain/v3/x/iid/types.DIDFragment"
"github.com/ixofoundation/ixo-blockchain/v4/x/iid/types.DIDFragment"
];
string function_type = 6;
repeated FunctionParam function_parameters = 7 [
Expand Down Expand Up @@ -108,7 +108,7 @@ message Bond {
string bond_did = 27;
string oracle_did = 28 [
(gogoproto.casttype) =
"github.com/ixofoundation/ixo-blockchain/v3/x/iid/types.DIDFragment"
"github.com/ixofoundation/ixo-blockchain/v4/x/iid/types.DIDFragment"
];
}

Expand All @@ -117,7 +117,7 @@ message Bond {
message BaseOrder {
string account_did = 1 [
(gogoproto.casttype) =
"github.com/ixofoundation/ixo-blockchain/v3/x/iid/types.DIDFragment"
"github.com/ixofoundation/ixo-blockchain/v4/x/iid/types.DIDFragment"
];
cosmos.base.v1beta1.Coin amount = 2 [ (gogoproto.nullable) = false ];
bool cancelled = 3;
Expand Down
2 changes: 1 addition & 1 deletion proto/ixo/bonds/v1beta1/event.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package ixo.bonds.v1beta1;

option go_package = "github.com/ixofoundation/ixo-blockchain/v3/x/bonds/types";
option go_package = "github.com/ixofoundation/ixo-blockchain/v4/x/bonds/types";

import "gogoproto/gogo.proto";
import "ixo/bonds/v1beta1/bonds.proto";
Expand Down
2 changes: 1 addition & 1 deletion proto/ixo/bonds/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package ixo.bonds.v1beta1;
import "gogoproto/gogo.proto";
import "ixo/bonds/v1beta1/bonds.proto";

option go_package = "github.com/ixofoundation/ixo-blockchain/v3/x/bonds/types";
option go_package = "github.com/ixofoundation/ixo-blockchain/v4/x/bonds/types";

// GenesisState defines the bonds module's genesis state.
message GenesisState {
Expand Down
2 changes: 1 addition & 1 deletion proto/ixo/bonds/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "ixo/bonds/v1beta1/bonds.proto";

option go_package = "github.com/ixofoundation/ixo-blockchain/v3/x/bonds/types";
option go_package = "github.com/ixofoundation/ixo-blockchain/v4/x/bonds/types";

// Query defines the gRPC querier service.
service Query {
Expand Down
Loading

0 comments on commit c6939f1

Please sign in to comment.