Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add test grandpa #28

Merged
merged 3 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ _build/
mytestnet/

screenlog.0
.idea
.idea


node_modules
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,16 @@ test-upgrade: clean-testing-data

clean-testing-data:
@echo "Killing binary and removing previous data"
echo "stopping picachain..."
-@pkill picad 2>/dev/null
-@pkill rly 2>/dev/null
-@rm -rf ./mytestnet

echo "stopping parachain..."
-@killall parachain-node
-@killall polkadot

netstat -ltup | grep LISTEN

.PHONY: ictest-start-cosmos ictest-start-polkadot ictest-ibc ictest-push-wasm ictest-all

include contrib/make/release.mk
Expand All @@ -181,12 +187,6 @@ test-upgrade: clean-testing-data
./scripts/tweak-test-upgrade.sh


clean-testing-data:
@echo "Killing binary and removing previous data"
-@pkill centaurid 2>/dev/null
-@pkill picad 2>/dev/null
-@rm -rf ./screenlog.0
-@rm -rf ./mytestnet

## Scripts for testing sdk 50
init-deps:
Expand All @@ -200,9 +200,9 @@ localnet-pica:
bash ./scripts/run-node.sh picad
bash ./scripts/50/store-wasm-code.sh

localnet-picasso:
localnet-parachain:
@echo "Starting localnet"
bash ./scripts/relayer_hyperspace/run-picasso.sh
bash ./scripts/upgrade/setup-polkadot-node.sh

relayer-create-clients:
@echo "Starting relayer"
Expand Down
2 changes: 1 addition & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac
keyTable := ibcclienttypes.ParamKeyTable()
keyTable.RegisterParamSet(&ibcconnectiontypes.Params{})
paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable())
paramsKeeper.Subspace(icacontrollertypes.SubModuleName).WithKeyTable(icacontrollertypes.ParamKeyTable())
paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable())

Expand Down
5 changes: 4 additions & 1 deletion app/upgrades/v7_0_1/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package v7_0_1

import (
"context"
upgradetypes "cosmossdk.io/x/upgrade/types"
"encoding/hex"
"fmt"

upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand Down Expand Up @@ -53,6 +54,8 @@ func CreateUpgradeHandler(
listCheckSum = append(listCheckSum, checksumStr)
}

// Register SendEnabled for legacy subspace

checksum := types.Checksums{Checksums: listCheckSum}
bz, err := codec.Marshal(&checksum)
if err != nil {
Expand Down
39 changes: 39 additions & 0 deletions scripts/polkadot-js/getter/get_balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ApiPromise, WsProvider } from "@polkadot/api";
import { getProvider, getWallets } from "../utils/indexer";

// Put the address of the account you want to fetch info for here

async function fetchAccountInfo() {
// Initialise the provider to connect to the local node

// Create the API instance
const api = await getProvider();

const wallets = getWallets();
try {
// Fetch the account info
const accountInfo = await api.query.system.account(wallets.alice.address);

console.log(
`Account ${wallets.alice.address} info:`,
accountInfo.toHuman()
);
} catch (error) {
console.error("Error fetching account info:", error);
}

try {
const bobAccountInfo = await api.query.system.account(wallets.bob.address);
console.log(
`Account ${wallets.bob.address} info:`,
bobAccountInfo.toHuman()
);
} catch (error) {
console.error("Error fetching account info:", error);
} finally {
// Disconnect the provider when done
api.disconnect();
}
}

fetchAccountInfo();
88 changes: 88 additions & 0 deletions scripts/polkadot-js/getter/list_method_params.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { ApiPromise } from "@polkadot/api";
import { getProvider } from "../utils/indexer";

async function run() {
const api = await getProvider();
await listTxMethods(api);
}
type MetadataV14 = {
magicNumber: string;
metadata: {
v14: {
lookup: {
types: [
{
id: string;
type: {
path: string[];
params: object[];
def: object;
docs: string[];
};
}
];
};
pallets: Array<{
name: string;
calls?: Array<{
name: string;
args: Array<{
name: string;
type: string | number; // Depending on how types are represented, you might need to adjust this
}>;
}>;
}>;
extrinsic: object;
type: string;
};
};
};

async function listTxMethods(api: ApiPromise) {
console.log("\nTransaction Methods:");
const metadata = await api.rpc.state.getMetadata();

const metadataV14 = metadata.toJSON() as {
magicNumber: string;
metadata: {
v14: {
lookup: {
types: [
{
id: string;
type: {
path: string[];
params: object[];
def: object;
docs: string[];
};
}
];
};
pallets: Array<any>;
extrinsic: object;
type: string;
};
};
};

console.log("pallets: ", metadataV14.metadata.v14.pallets);
// Usage example, assuming you have metadataV14 of type MetadataV14
const ibcModule = metadataV14.metadata.v14.pallets.find(
(pallet) => pallet.name === "Ibc"
);

if (ibcModule && ibcModule.calls) {
const transferMethod = ibcModule.calls.find(
(call: any) => call.name === "transfer"
);
if (transferMethod) {
console.log(`Parameters for ibc.transfer:`);
transferMethod.args.forEach((arg: any) => {
console.log(`${arg.name}: ${arg.type}`);
});
}
}
}

run().catch(console.error);
33 changes: 33 additions & 0 deletions scripts/polkadot-js/getter/list_rpc_methods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ApiPromise, WsProvider } from "@polkadot/api";
import { getProvider, getWallets } from "../utils/indexer";

// Put the address of the account you want to fetch info for here

async function run() {
// Initialise the provider to connect to the local node

// Create the API instance
const api = await getProvider();

listTxMethods(api);
}

run();

function listTxMethods(api: ApiPromise) {
console.log("\nTransaction Methods:");
Object.keys(api.tx).forEach((module) => {
Object.keys(api.tx[module]).forEach((method) => {
console.log(`${module}.${method}`);
});
});
}

function listQueryMethods(api: ApiPromise) {
console.log("\nQuery Methods:");
Object.keys(api.query).forEach((module) => {
Object.keys(api.query[module]).forEach((method) => {
console.log(`${module}.${method}`);
});
});
}
13 changes: 13 additions & 0 deletions scripts/polkadot-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "polkadot-js",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"typescript": "^5.4.5"
},
"dependencies": {
"@polkadot/api": "^10.12.6",
"@polkadot/keyring": "^12.6.2"
}
}
109 changes: 109 additions & 0 deletions scripts/polkadot-js/src/ibc-transfer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { ApiPromise, WsProvider } from "@polkadot/api";
import { Keyring } from "@polkadot/keyring";
import BN from "bn.js";
import { KeyringPair } from "@polkadot/keyring/types";
import { getProvider, getWallets } from "../utils/indexer";

async function sendIbcFundsTx(
api: ApiPromise,
senderKeypair: KeyringPair,
channelID: string,
amount: { denom: string; amount: string; address: string },
options: any
) {
{
// Ensure the API is connected
if (!api.isConnected) {
await api.connect();
}

// Calculate the timestamp for 5 minutes into the future
const fiveMinutes = 5 * 60 * 1000; // 5 minutes in milliseconds
const futureTimestamp = new Date().getTime() + fiveMinutes; // Current time + 5 minutes

const substrateFutureTimestamp = api.createType("u64", futureTimestamp);

// dont have to convert
const to = { Raw: amount.address };

const assetNum = 1;
const sourceChannel = 0;
const timeout = {
Offset: {
timestamp: api.createType("Option<u64>", substrateFutureTimestamp), // or provide a specific timestamp offset
},
};

// Construct paramters
const params = {
to,
source_channel: sourceChannel,
timeout,
};

const assetId = new BN(assetNum);
const amountBN = new BN(amount.amount, 10);
const memo = null;

// Make the call to ibc.transfer with the transferObj
const call = api.tx.ibc.transfer(params, assetId, amountBN, memo);
// Sign and send the transaction
return await new Promise((resolve, reject) => {
call
.signAndSend(
senderKeypair,
{ nonce: -1 },
({ status, dispatchError }) => {
if (status.isInBlock || status.isFinalized) {
if (dispatchError) {
if (dispatchError.isModule) {
// For module errors, we have the section indexed, lookup
const decoded = api.registry.findMetaError(
dispatchError.asModule
);
const { docs, name, section } = decoded;
reject(new Error(`${section}.${name}: ${docs.join(" ")}`));
} else {
// Other, CannotLookup, BadOrigin, no extra info
reject(new Error(dispatchError.toString()));
}
} else {
resolve(status.asFinalized.toString());
}
}
}
)
.catch(reject);
});
}
}
// Example usage
async function main() {
const api = await getProvider();
const wallets = getWallets();
const senderKeypair = wallets.alice;

const channelID = "0";
const amount = {
denom: "1",
amount: "1000000000000000",
address: "pica1hj5fveer5cjtn4wd6wstzugjfdxzl0xpas3hgy",
};

const options = {};

try {
const hash = await sendIbcFundsTx(
api,
senderKeypair,
channelID,
amount,
options
);
console.log("Transaction hash:", hash);
} catch (error) {
console.error("Error sending IBC funds:", error);
}
}

main().catch(console.error);
25 changes: 25 additions & 0 deletions scripts/polkadot-js/src/simple-connect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Required imports
import { ApiPromise, WsProvider } from "@polkadot/api";

async function main() {
// Initialise the provider to connect to the local node
const provider = new WsProvider("ws://127.0.0.1:9944");

// Create the API and wait until ready
const api = await ApiPromise.create({ provider });

// Retrieve the chain & node information via rpc calls
const [chain, nodeName, nodeVersion] = await Promise.all([
api.rpc.system.chain(),
api.rpc.system.name(),
api.rpc.system.version(),
]);

console.log(
`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`
);
}

main()
.catch(console.error)
.finally(() => process.exit());
Loading
Loading