Skip to content

Commit

Permalink
CSUB-708: Added UnverifiedBlockTime constant to runtime (#1343)
Browse files Browse the repository at this point in the history
* added UnverifiedBlockTime constant to runtime

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Auto-update creditcoin-js type definitions

* updated unverifiedTaskTimeout to be read as u32

* formatted

---------

Co-authored-by: Zachary Frederick <zach.frederick@gluwa.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: gluwa-bot <creditcoin@gluwa.com>
  • Loading branch information
4 people authored Sep 25, 2023
1 parent 9fbf4ef commit 29d3207
Show file tree
Hide file tree
Showing 13 changed files with 1,773 additions and 44 deletions.
2 changes: 1 addition & 1 deletion creditcoin-js/creditcoin.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion creditcoin-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "creditcoin-js",
"version": "0.10.1",
"version": "0.10.4",
"author": "Jeremy Frank <support@gluwa.com>",
"license": "MIT",
"main": "lib/index.js",
Expand Down
7 changes: 7 additions & 0 deletions creditcoin-js/src/interfaces/augment-api-consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ declare module '@polkadot/api-base/types/consts' {
**/
[key: string]: Codec;
};
creditcoin: {
unverifiedTaskTimeout: u32 & AugmentedConst<ApiType>;
/**
* Generic const
**/
[key: string]: Codec;
};
fastUnstake: {
/**
* Deposit to take for unstaking, to make sure we're able to slash the it in order to cover
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@polkadot/keyring": "12.4.2",
"@types/ws": "^8.5.3",
"axios": "^1.0.0",
"creditcoin-js": "file:../creditcoin-js/creditcoin-js-v0.10.1.tgz",
"creditcoin-js": "file:../creditcoin-js/creditcoin-js-v0.10.4.tgz",
"ws": "^8.5.0"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2182,9 +2182,9 @@ create-require@^1.1.0:
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==

"creditcoin-js@file:../creditcoin-js/creditcoin-js-v0.10.1.tgz":
version "0.10.1"
resolved "file:../creditcoin-js/creditcoin-js-v0.10.1.tgz#5d63d2f9ac55175870f0a07e58ab05564867d80c"
"creditcoin-js@file:../creditcoin-js/creditcoin-js-v0.10.4.tgz":
version "0.10.4"
resolved "file:../creditcoin-js/creditcoin-js-v0.10.4.tgz#78d4c8e4b0b6562537bfd110f0017ea7c65d4db1"
dependencies:
"@polkadot/api" "9.14.2"
ethers "^5.7.1"
Expand Down
1 change: 1 addition & 0 deletions pallets/creditcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub mod pallet {
+ ethereum_types::BigEndianHash<Uint = sp_core::U256>
+ Clone;

#[pallet::constant]
type UnverifiedTaskTimeout: Get<<Self as frame_system::Config>::BlockNumber>;

type WeightInfo: WeightInfo;
Expand Down
2 changes: 1 addition & 1 deletion scripts/cc-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dependencies": {
"cli-table3": "^0.6.3",
"commander": "^11.0.0",
"creditcoin-js": "file:../../creditcoin-js/creditcoin-js-v0.10.1.tgz",
"creditcoin-js": "file:../../creditcoin-js/creditcoin-js-v0.10.4.tgz",
"prompts": "^2.4.2",
"web3-validator": "^2.0.1"
},
Expand Down
10 changes: 9 additions & 1 deletion scripts/cc-cli/src/commands/collectCoins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { requiredInput } from "../utils/parsing";
import { isAddress } from "web3-validator";
import { utils } from "ethers";
import chalk from "chalk";
import { U64, U32 } from "@polkadot/types-codec";

export function makeCollectCoinsCmd() {
const externalAddressOpt = new Option(
Expand Down Expand Up @@ -44,6 +45,7 @@ async function collectCoinsAction(options: OptionValues) {
validateOptsOrExit(options);

const {
api,
extrinsics: { requestCollectCoins },
} = await newApi(options.url);
const signer = await initCallerKeyring(options);
Expand All @@ -53,7 +55,13 @@ async function collectCoinsAction(options: OptionValues) {
signer,
options.burnTxHash,
);
await event.waitForVerification(800_000);

const blockTime = (api.consts.babe.expectedBlockTime as U64).toNumber();
const unverifiedTaskTimeout = (
api.consts.creditcoin.unverifiedTaskTimeout as U32
).toNumber();

await event.waitForVerification(blockTime * unverifiedTaskTimeout);
}

function validateOptsOrExit(options: OptionValues) {
Expand Down
21 changes: 12 additions & 9 deletions scripts/cc-cli/src/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,19 @@ export async function setAuthorities() {
await api.disconnect();
}

export function retry(retries: any, executor: any): any {
console.log(`${retries as string} retries left!`);

if (typeof retries !== "number") {
throw new TypeError("retries is not a number");
export async function retry<T>(
retries: number,
func: () => PromiseLike<T>,
): Promise<T> {
console.log(`${retries} retries left!`);
try {
return await func();
} catch (error) {
if (retries > 0) {
return await retry(retries - 1, func);
}
throw error;
}

return new Promise(executor).catch((error) =>
retries > 0 ? retry(retries - 1, executor) : Promise.reject(error),
);
}

function setup() {
Expand Down
10 changes: 5 additions & 5 deletions scripts/cc-cli/src/test/integration-tests/collectCoins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ describeIf(arg("CREDITCOIN_EXECUTE_SETUP_AUTHORITY"), "collect-coins", () => {
process.env.CREDITCOIN_CTC_BURN_TX_HASH,
);

await retry(5, async (resolve: any, reject: any) => {
await setAuthorities().then(resolve).catch(reject);
}).catch(() => {
console.log("Could not setup testing authorities");
try {
await retry(5, setAuthorities);
} catch (reason: any) {
console.log(`Could not setup testing authorities: ${reason as string}`);
process.exit(1);
});
}

await cryptoWaitReady();

Expand Down
6 changes: 3 additions & 3 deletions scripts/cc-cli/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2299,9 +2299,9 @@ create-require@^1.1.0:
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==

"creditcoin-js@file:../../creditcoin-js/creditcoin-js-v0.10.1.tgz":
version "0.10.1"
resolved "file:../../creditcoin-js/creditcoin-js-v0.10.1.tgz#ad9f04d6e50d31398f9b3fcf0cb949cf223dbe1f"
"creditcoin-js@file:../../creditcoin-js/creditcoin-js-v0.10.4.tgz":
version "0.10.4"
resolved "file:../../creditcoin-js/creditcoin-js-v0.10.4.tgz#78d4c8e4b0b6562537bfd110f0017ea7c65d4db1"
dependencies:
"@polkadot/api" "9.14.2"
ethers "^5.7.1"
Expand Down
2 changes: 1 addition & 1 deletion scripts/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@types/ws": "^8.5.3",
"axios": "^1.1.2",
"creditcoin-js": "file:../../creditcoin-js/creditcoin-js-v0.10.1.tgz",
"creditcoin-js": "file:../../creditcoin-js/creditcoin-js-v0.10.4.tgz",
"ws": "^8.5.0"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 29d3207

Please sign in to comment.