From b623e3516d59e14f1979ff0da5572d87dd771884 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Tue, 12 Nov 2024 12:40:20 +0200 Subject: [PATCH 01/26] fix: FeesTreasuryProportion is only applied to substrate based tx only --- runtime/moonbase/src/lib.rs | 12 ++++++++---- runtime/moonbeam/src/lib.rs | 12 ++++++++---- runtime/moonriver/src/lib.rs | 12 ++++++++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index be2fd23073..7c699860f6 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -364,9 +364,9 @@ where mut fees_then_tips: impl Iterator>>, ) { if let Some(fees) = fees_then_tips.next() { - let treasury_perbill = + let treasury_proportion = runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); - let treasury_part = treasury_perbill.deconstruct(); + let treasury_part = treasury_proportion.deconstruct(); let burn_part = Perbill::one().deconstruct() - treasury_part; let (_, to_treasury) = fees.ration(burn_part, treasury_part); // Balances pallet automatically burns dropped Credits by decreasing @@ -378,7 +378,7 @@ where // handle tip if there is one if let Some(tip) = fees_then_tips.next() { // for now we use the same burn/treasury strategy used for regular fees - let (_, to_treasury) = tip.ration(80, 20); + let (_, to_treasury) = tip.ration(burn_part, treasury_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced( to_treasury, ); @@ -391,7 +391,11 @@ where fn on_nonzero_unbalanced(amount: Credit>) { // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly - let (_, to_treasury) = amount.ration(80, 20); + let treasury_proportion = + runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); + let treasury_part = treasury_proportion.deconstruct(); + let burn_part = Perbill::one().deconstruct() - treasury_part; + let (_, to_treasury) = amount.ration(burn_part, treasury_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced(to_treasury); } } diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index a8ca7810a8..91635966c5 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -352,9 +352,9 @@ where mut fees_then_tips: impl Iterator>>, ) { if let Some(fees) = fees_then_tips.next() { - let treasury_perbill = + let treasury_proportion = runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); - let treasury_part = treasury_perbill.deconstruct(); + let treasury_part = treasury_proportion.deconstruct(); let burn_part = Perbill::one().deconstruct() - treasury_part; let (_, to_treasury) = fees.ration(burn_part, treasury_part); // Balances pallet automatically burns dropped Credits by decreasing @@ -366,7 +366,7 @@ where // handle tip if there is one if let Some(tip) = fees_then_tips.next() { // for now we use the same burn/treasury strategy used for regular fees - let (_, to_treasury) = tip.ration(80, 20); + let (_, to_treasury) = tip.ration(burn_part, treasury_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced( to_treasury, ); @@ -379,7 +379,11 @@ where fn on_nonzero_unbalanced(amount: Credit>) { // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly - let (_, to_treasury) = amount.ration(80, 20); + let treasury_proportion = + runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); + let treasury_part = treasury_proportion.deconstruct(); + let burn_part = Perbill::one().deconstruct() - treasury_part; + let (_, to_treasury) = amount.ration(burn_part, treasury_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced(to_treasury); } } diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index ad68874966..bd9776892e 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -354,9 +354,9 @@ where mut fees_then_tips: impl Iterator>>, ) { if let Some(fees) = fees_then_tips.next() { - let treasury_perbill = + let treasury_proportion = runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); - let treasury_part = treasury_perbill.deconstruct(); + let treasury_part = treasury_proportion.deconstruct(); let burn_part = Perbill::one().deconstruct() - treasury_part; let (_, to_treasury) = fees.ration(burn_part, treasury_part); // Balances pallet automatically burns dropped Credits by decreasing @@ -368,7 +368,7 @@ where // handle tip if there is one if let Some(tip) = fees_then_tips.next() { // for now we use the same burn/treasury strategy used for regular fees - let (_, to_treasury) = tip.ration(80, 20); + let (_, to_treasury) = tip.ration(burn_part, treasury_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced( to_treasury, ); @@ -381,7 +381,11 @@ where fn on_nonzero_unbalanced(amount: Credit>) { // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly - let (_, to_treasury) = amount.ration(80, 20); + let treasury_proportion = + runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); + let treasury_part = treasury_proportion.deconstruct(); + let burn_part = Perbill::one().deconstruct() - treasury_part; + let (_, to_treasury) = amount.ration(burn_part, treasury_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced(to_treasury); } } From 28712c6a6b3a4a80292103396db3f0c4478eb1ec Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Tue, 12 Nov 2024 14:45:08 +0200 Subject: [PATCH 02/26] refactor: split test into 2 files --- .../test-parameters-randomness.ts | 64 +++++++++++++++++++ .../test-parameters/test-parameters.ts | 64 +++---------------- 2 files changed, 72 insertions(+), 56 deletions(-) create mode 100644 test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts new file mode 100644 index 0000000000..7eb3afc799 --- /dev/null +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts @@ -0,0 +1,64 @@ +import {describeSuite, expect} from "@moonwall/cli"; +import {alith} from "@moonwall/util"; +import {fail} from "assert"; +import {parameterType, UNIT} from "./test-parameters"; + +describeSuite({ + id: "DTemp02", + title: "Parameters - Pallet Randomness", + foundationMethods: "dev", + testCases: ({it, context, log}) => { + it({ + id: `T01 - PalletRandomness - Deposit - CustomTests`, + title: "Deposit parameter should only be accepted in bounds", + test: async () => { + const MIN = 1n * UNIT; + const MAX = 1000n * UNIT; + + // used as an acceptable value + const AVG = (MIN + MAX) / 2n; + + const param1 = parameterType(context, "PalletRandomness", "Deposit", MIN - 1n); + try { + await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param1.toU8a())) + .signAsync(alith), + {allowFailures: false} + ); + fail("An extrinsic should not be created, since the parameter is invalid"); + } catch (error) { + expect(error.toString().toLowerCase()).to.contain("value out of bounds"); + } + + const param2 = parameterType(context, "PalletRandomness", "Deposit", MAX + 1n); + try { + await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param2.toU8a())) + .signAsync(alith), + {allowFailures: false} + ); + fail("An extrinsic should not be created, since the parameter is invalid"); + } catch (error) { + expect(error.toString().toLowerCase()).to.contain("value out of bounds"); + } + + const param3 = parameterType(context, "PalletRandomness", "Deposit", AVG); + const res3 = await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param3.toU8a())) + .signAsync(alith), + {allowFailures: false} + ); + expect( + res3.result?.successful, + "An extrinsic should be created, since the parameter is valid" + ).to.be.true; + }, + }); + }, +}); \ No newline at end of file diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters.ts b/test/suites/dev/moonbase/test-parameters/test-parameters.ts index 46638a2be7..b7ba2cc141 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters.ts @@ -2,13 +2,13 @@ import { describeSuite, DevModeContext, expect } from "@moonwall/cli"; import "@moonbeam-network/api-augment"; import { alith } from "@moonwall/util"; import { fail } from "assert"; -const UNIT = 1_000_000_000_000_000_000n; +export const UNIT = 1_000_000_000_000_000_000n; const RUNTIME = "MoonbaseRuntime"; const CRATE = "RuntimeParams"; const ALL_PARAMS = "DynamicParams"; -function parameterType(context: DevModeContext, module: string, name: string, value: unknown) { +export function parameterType(context: DevModeContext, module: string, name: string, value: unknown) { const paramWrapper = context .polkadotJs() .createType(`${RUNTIME}${CRATE}${ALL_PARAMS}${module}Parameters`, { @@ -22,7 +22,7 @@ function parameterType(context: DevModeContext, module: string, name: string, va return runtimeParameter; } -function parameterKey(context: DevModeContext, module: string, name: string) { +export function parameterKey(context: DevModeContext, module: string, name: string) { const key = context .polkadotJs() .createType(`${RUNTIME}${CRATE}${ALL_PARAMS}${module}ParametersKey`, { @@ -82,60 +82,12 @@ describeSuite({ }); } - testParam("RuntimeConfig", "FeesTreasuryProportion", ["Perbill", 200_000_000]); - testParam("PalletRandomness", "Deposit", ["u128", UNIT * 100n]); - - it({ - id: `T${testCounter++} - PalletRandomness - Deposit - CustomTests`, - title: "Deposit parameter should only be accepted in bounds", - test: async () => { - const MIN = 1n * UNIT; - const MAX = 1000n * UNIT; - // used as an acceptable value - const AVG = (MIN + MAX) / 2n; - - const param1 = parameterType(context, "PalletRandomness", "Deposit", MIN - 1n); - try { - await context.createBlock( - context - .polkadotJs() - .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param1.toU8a())) - .signAsync(alith), - { allowFailures: false } - ); - fail("An extrinsic should not be created, since the parameter is invalid"); - } catch (error) { - expect(error.toString().toLowerCase()).to.contain("value out of bounds"); - } + // Add all the parameters here to test against 2 test cases: + // 1. Parameters cannot by a normal user. + // 2. Parameters can be set by sudo. - const param2 = parameterType(context, "PalletRandomness", "Deposit", MAX + 1n); - try { - await context.createBlock( - context - .polkadotJs() - .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param2.toU8a())) - .signAsync(alith), - { allowFailures: false } - ); - fail("An extrinsic should not be created, since the parameter is invalid"); - } catch (error) { - expect(error.toString().toLowerCase()).to.contain("value out of bounds"); - } - - const param3 = parameterType(context, "PalletRandomness", "Deposit", AVG); - const res3 = await context.createBlock( - context - .polkadotJs() - .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param3.toU8a())) - .signAsync(alith), - { allowFailures: false } - ); - expect( - res3.result?.successful, - "An extrinsic should be created, since the parameter is valid" - ).to.be.true; - }, - }); + testParam("RuntimeConfig", "FeesTreasuryProportion", ["Perbill", 200_000_000]); + testParam("PalletRandomness", "Deposit", ["u128", UNIT * 100n]); }, }); From 8d477f9adf0661357e8c297c9c92672b4a4d2ed6 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Tue, 12 Nov 2024 14:45:29 +0200 Subject: [PATCH 03/26] test: test 0% FeesTreasuryProportion --- .../test-parameters-runtime.ts | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts new file mode 100644 index 0000000000..b16e316345 --- /dev/null +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts @@ -0,0 +1,71 @@ +import {describeSuite, expect, TransactionTypes} from "@moonwall/cli"; +import { + alith, + BALTATHAR_ADDRESS, + createRawTransfer, + extractFee, + TREASURY_ACCOUNT +} from "@moonwall/util"; +import {fail} from "assert"; +import {parameterType, UNIT} from "./test-parameters"; + +describeSuite({ + id: "DTemp02", + title: "Parameters - RuntimeConfig", + foundationMethods: "dev", + testCases: ({it, context, log,}) => { + let testCounter = 0; + + + it({ + id: `T${++testCounter}`, + title: "treasury should be empty at genesis", + test: async () => { + expect( + await context.viem().getBalance({address: TREASURY_ACCOUNT}), + "Treasury account should be initially empty" + ).to.equal(0n); + }, + }); + + + for (const txnType of TransactionTypes) { + it({ + id: `T${++testCounter}`, + title: `should send 0% of fees to treasury for ${txnType} transfers`, + test: async () => { + const param = parameterType(context, "RuntimeConfig", "FeesTreasuryProportion", 0); + await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a())) + .signAsync(alith), + {allowFailures: false} + ); + + const balBefore = await context.viem().getBalance({address: TREASURY_ACCOUNT}); + const issuanceBefore = ( + await context.polkadotJs().query.balances.totalIssuance() + ).toBigInt(); + const {result} = await context.createBlock( + await createRawTransfer(context, BALTATHAR_ADDRESS, 128, {type: txnType}) + ); + + const balAfter = await context.viem().getBalance({address: TREASURY_ACCOUNT}); + const issuanceAfter = ( + await context.polkadotJs().query.balances.totalIssuance() + ).toBigInt(); + + const treasuryIncrease = balAfter - balBefore; + const fee = extractFee(result?.events)!.amount.toBigInt(); + expect(fee / treasuryIncrease, "0% of the fees should go to treasury").to.equal(0n); + + const issuanceDecrease = issuanceBefore - issuanceAfter; + expect((fee * 100n) / issuanceDecrease, "100% of the fees should be burned").to.equal( + 100n + ); + }, + }); + } + }, +}); \ No newline at end of file From 5e8f02bf392bfb2cfe4feb26c0e73262c2ceb0bf Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Tue, 12 Nov 2024 15:01:56 +0200 Subject: [PATCH 04/26] fix --- .../dev/moonbase/test-parameters/test-parameters-runtime.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts index b16e316345..fb5d86c4c6 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts @@ -58,7 +58,7 @@ describeSuite({ const treasuryIncrease = balAfter - balBefore; const fee = extractFee(result?.events)!.amount.toBigInt(); - expect(fee / treasuryIncrease, "0% of the fees should go to treasury").to.equal(0n); + expect(treasuryIncrease, "0% of the fees should go to treasury").to.equal(0n); const issuanceDecrease = issuanceBefore - issuanceAfter; expect((fee * 100n) / issuanceDecrease, "100% of the fees should be burned").to.equal( From 9b7c1f2c407bf1bec9a9450c54f99c3a2f47867e Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Tue, 12 Nov 2024 21:26:19 +0200 Subject: [PATCH 05/26] fix --- .../test-parameters/test-parameters-runtime.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts index fb5d86c4c6..35a322a51f 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts @@ -16,19 +16,6 @@ describeSuite({ testCases: ({it, context, log,}) => { let testCounter = 0; - - it({ - id: `T${++testCounter}`, - title: "treasury should be empty at genesis", - test: async () => { - expect( - await context.viem().getBalance({address: TREASURY_ACCOUNT}), - "Treasury account should be initially empty" - ).to.equal(0n); - }, - }); - - for (const txnType of TransactionTypes) { it({ id: `T${++testCounter}`, From 99245d6a4921b3b442c9cf80a5319f879603e840 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Tue, 12 Nov 2024 21:32:58 +0200 Subject: [PATCH 06/26] fix --- .../test-parameters/test-parameters-runtime.ts | 3 +-- .../dev/moonbase/test-parameters/test-parameters.ts | 13 +++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts index 35a322a51f..0bb23ed47c 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts @@ -6,8 +6,7 @@ import { extractFee, TREASURY_ACCOUNT } from "@moonwall/util"; -import {fail} from "assert"; -import {parameterType, UNIT} from "./test-parameters"; +import {parameterType} from "./test-parameters"; describeSuite({ id: "DTemp02", diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters.ts b/test/suites/dev/moonbase/test-parameters/test-parameters.ts index b7ba2cc141..17ec8cf95c 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters.ts @@ -1,7 +1,7 @@ -import { describeSuite, DevModeContext, expect } from "@moonwall/cli"; +import {describeSuite, DevModeContext, expect} from "@moonwall/cli"; import "@moonbeam-network/api-augment"; -import { alith } from "@moonwall/util"; -import { fail } from "assert"; +import {alith} from "@moonwall/util"; + export const UNIT = 1_000_000_000_000_000_000n; const RUNTIME = "MoonbaseRuntime"; @@ -40,8 +40,9 @@ describeSuite({ id: "DTemp01", title: "Parameters", foundationMethods: "dev", - testCases: ({ it, context, log }) => { + testCases: ({it, context, log}) => { let testCounter = 0; + function testParam(module: string, name: string, valueCreation: [string, unknown]) { it({ id: `T${testCounter++} - ${module} - ${name}`, @@ -52,7 +53,7 @@ describeSuite({ const res = await context.createBlock( context.polkadotJs().tx.parameters.setParameter(param.toU8a()).signAsync(alith), - { allowFailures: true } + {allowFailures: true} ); expect(res.result?.error?.name).toEqual("BadOrigin"); }, @@ -70,7 +71,7 @@ describeSuite({ .polkadotJs() .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a())) .signAsync(alith), - { allowFailures: false } + {allowFailures: false} ); const key = parameterKey(context, module, name); From 6f1a1210826ced74024c9f2520b3df6725e89cdc Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Tue, 12 Nov 2024 21:36:57 +0200 Subject: [PATCH 07/26] fix --- .../test-parameters-randomness.ts | 18 ++++++++--------- .../test-parameters-runtime.ts | 20 +++++++++---------- .../test-parameters/test-parameters.ts | 18 ++++++++++------- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts index 7eb3afc799..269492bc13 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts @@ -1,13 +1,13 @@ -import {describeSuite, expect} from "@moonwall/cli"; -import {alith} from "@moonwall/util"; -import {fail} from "assert"; -import {parameterType, UNIT} from "./test-parameters"; +import { describeSuite, expect } from "@moonwall/cli"; +import { alith } from "@moonwall/util"; +import { fail } from "assert"; +import { parameterType, UNIT } from "./test-parameters"; describeSuite({ id: "DTemp02", title: "Parameters - Pallet Randomness", foundationMethods: "dev", - testCases: ({it, context, log}) => { + testCases: ({ it, context, log }) => { it({ id: `T01 - PalletRandomness - Deposit - CustomTests`, title: "Deposit parameter should only be accepted in bounds", @@ -25,7 +25,7 @@ describeSuite({ .polkadotJs() .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param1.toU8a())) .signAsync(alith), - {allowFailures: false} + { allowFailures: false } ); fail("An extrinsic should not be created, since the parameter is invalid"); } catch (error) { @@ -39,7 +39,7 @@ describeSuite({ .polkadotJs() .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param2.toU8a())) .signAsync(alith), - {allowFailures: false} + { allowFailures: false } ); fail("An extrinsic should not be created, since the parameter is invalid"); } catch (error) { @@ -52,7 +52,7 @@ describeSuite({ .polkadotJs() .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param3.toU8a())) .signAsync(alith), - {allowFailures: false} + { allowFailures: false } ); expect( res3.result?.successful, @@ -61,4 +61,4 @@ describeSuite({ }, }); }, -}); \ No newline at end of file +}); diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts index 0bb23ed47c..160b8a9945 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts @@ -1,18 +1,18 @@ -import {describeSuite, expect, TransactionTypes} from "@moonwall/cli"; +import { describeSuite, expect, TransactionTypes } from "@moonwall/cli"; import { alith, BALTATHAR_ADDRESS, createRawTransfer, extractFee, - TREASURY_ACCOUNT + TREASURY_ACCOUNT, } from "@moonwall/util"; -import {parameterType} from "./test-parameters"; +import { parameterType } from "./test-parameters"; describeSuite({ id: "DTemp02", title: "Parameters - RuntimeConfig", foundationMethods: "dev", - testCases: ({it, context, log,}) => { + testCases: ({ it, context, log }) => { let testCounter = 0; for (const txnType of TransactionTypes) { @@ -26,18 +26,18 @@ describeSuite({ .polkadotJs() .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a())) .signAsync(alith), - {allowFailures: false} + { allowFailures: false } ); - const balBefore = await context.viem().getBalance({address: TREASURY_ACCOUNT}); + const balBefore = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); const issuanceBefore = ( await context.polkadotJs().query.balances.totalIssuance() ).toBigInt(); - const {result} = await context.createBlock( - await createRawTransfer(context, BALTATHAR_ADDRESS, 128, {type: txnType}) + const { result } = await context.createBlock( + await createRawTransfer(context, BALTATHAR_ADDRESS, 128, { type: txnType }) ); - const balAfter = await context.viem().getBalance({address: TREASURY_ACCOUNT}); + const balAfter = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); const issuanceAfter = ( await context.polkadotJs().query.balances.totalIssuance() ).toBigInt(); @@ -54,4 +54,4 @@ describeSuite({ }); } }, -}); \ No newline at end of file +}); diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters.ts b/test/suites/dev/moonbase/test-parameters/test-parameters.ts index 17ec8cf95c..fb1fbef96a 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters.ts @@ -1,6 +1,6 @@ -import {describeSuite, DevModeContext, expect} from "@moonwall/cli"; +import { describeSuite, DevModeContext, expect } from "@moonwall/cli"; import "@moonbeam-network/api-augment"; -import {alith} from "@moonwall/util"; +import { alith } from "@moonwall/util"; export const UNIT = 1_000_000_000_000_000_000n; @@ -8,7 +8,12 @@ const RUNTIME = "MoonbaseRuntime"; const CRATE = "RuntimeParams"; const ALL_PARAMS = "DynamicParams"; -export function parameterType(context: DevModeContext, module: string, name: string, value: unknown) { +export function parameterType( + context: DevModeContext, + module: string, + name: string, + value: unknown +) { const paramWrapper = context .polkadotJs() .createType(`${RUNTIME}${CRATE}${ALL_PARAMS}${module}Parameters`, { @@ -40,7 +45,7 @@ describeSuite({ id: "DTemp01", title: "Parameters", foundationMethods: "dev", - testCases: ({it, context, log}) => { + testCases: ({ it, context, log }) => { let testCounter = 0; function testParam(module: string, name: string, valueCreation: [string, unknown]) { @@ -53,7 +58,7 @@ describeSuite({ const res = await context.createBlock( context.polkadotJs().tx.parameters.setParameter(param.toU8a()).signAsync(alith), - {allowFailures: true} + { allowFailures: true } ); expect(res.result?.error?.name).toEqual("BadOrigin"); }, @@ -71,7 +76,7 @@ describeSuite({ .polkadotJs() .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a())) .signAsync(alith), - {allowFailures: false} + { allowFailures: false } ); const key = parameterKey(context, module, name); @@ -83,7 +88,6 @@ describeSuite({ }); } - // Add all the parameters here to test against 2 test cases: // 1. Parameters cannot by a normal user. // 2. Parameters can be set by sudo. From 4c35eb625b95cd7dc8c0662a36281fea78d8cd64 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Wed, 13 Nov 2024 12:36:50 +0200 Subject: [PATCH 08/26] Update test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts Co-authored-by: Rodrigo Quelhas <22591718+RomarQ@users.noreply.github.com> --- .../dev/moonbase/test-parameters/test-parameters-randomness.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts index 269492bc13..c112562d9a 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts @@ -41,7 +41,7 @@ describeSuite({ .signAsync(alith), { allowFailures: false } ); - fail("An extrinsic should not be created, since the parameter is invalid"); + expect.fail("An extrinsic should not be created, since the parameter is invalid"); } catch (error) { expect(error.toString().toLowerCase()).to.contain("value out of bounds"); } From 7f17edfbd39f20fe77643d6cc948cc3f32fb12ec Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Wed, 13 Nov 2024 12:36:57 +0200 Subject: [PATCH 09/26] Update test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts Co-authored-by: Rodrigo Quelhas <22591718+RomarQ@users.noreply.github.com> --- .../dev/moonbase/test-parameters/test-parameters-randomness.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts index c112562d9a..526e23d98e 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts @@ -27,7 +27,7 @@ describeSuite({ .signAsync(alith), { allowFailures: false } ); - fail("An extrinsic should not be created, since the parameter is invalid"); + expect.fail("An extrinsic should not be created, since the parameter is invalid"); } catch (error) { expect(error.toString().toLowerCase()).to.contain("value out of bounds"); } From 2841fc967b7c04ef806102325c4cbfe6e7c32367 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Wed, 13 Nov 2024 12:47:35 +0200 Subject: [PATCH 10/26] add substrate based tests --- .../test-parameters-runtime.ts | 89 ++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts index 160b8a9945..ad34971daa 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts @@ -1,6 +1,7 @@ import { describeSuite, expect, TransactionTypes } from "@moonwall/cli"; import { alith, + baltathar, BALTATHAR_ADDRESS, createRawTransfer, extractFee, @@ -18,7 +19,9 @@ describeSuite({ for (const txnType of TransactionTypes) { it({ id: `T${++testCounter}`, - title: `should send 0% of fees to treasury for ${txnType} transfers`, + title: + `Changing FeesTreasuryProportion to zero should send 0% of fees to treasury for` + + ` Ethereum ${txnType} transfers`, test: async () => { const param = parameterType(context, "RuntimeConfig", "FeesTreasuryProportion", 0); await context.createBlock( @@ -53,5 +56,89 @@ describeSuite({ }, }); } + + it({ + id: `T${++testCounter}`, + title: + `Changing FeesTreasuryProportion to zero should send 0% of fees to treasury for` + + ` Substrate based transactions with no tip`, + test: async () => { + const param = parameterType(context, "RuntimeConfig", "FeesTreasuryProportion", 0); + await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a())) + .signAsync(alith), + { allowFailures: false } + ); + + const balanceBefore = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); + const issuanceBefore = ( + await context.polkadotJs().query.balances.totalIssuance() + ).toBigInt(); + + const { result } = await context.createBlock( + context + .polkadotJs() + .tx.balances.transfer(alith.address, 128) + .signAsync(baltathar, { tip: 0 }), + { allowFailures: false } + ); + + const balanceAfter = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); + const issuanceAfter = ( + await context.polkadotJs().query.balances.totalIssuance() + ).toBigInt(); + + const treasuryIncrease = balanceAfter - balanceBefore; + const fee = extractFee(result?.events)!.amount.toBigInt(); + expect(treasuryIncrease, "0% of the fees should go to treasury").to.equal(0n); + + const issuanceDecrease = issuanceBefore - issuanceAfter; + expect((fee * 100n) / issuanceDecrease, "100% of the fees should be burned").to.equal(100n); + }, + }); + + it({ + id: `T${++testCounter}`, + title: + `Changing FeesTreasuryProportion to zero should send 0% of fees to treasury for` + + ` Substrate based transactions with tip`, + test: async () => { + const param = parameterType(context, "RuntimeConfig", "FeesTreasuryProportion", 0); + await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a())) + .signAsync(alith), + { allowFailures: false } + ); + + const balanceBefore = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); + const issuanceBefore = ( + await context.polkadotJs().query.balances.totalIssuance() + ).toBigInt(); + + const { result } = await context.createBlock( + context + .polkadotJs() + .tx.balances.transfer(alith.address, 128) + .signAsync(baltathar, { tip: 128 }), + { allowFailures: false } + ); + + const balanceAfter = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); + const issuanceAfter = ( + await context.polkadotJs().query.balances.totalIssuance() + ).toBigInt(); + + const treasuryIncrease = balanceAfter - balanceBefore; + const fee = extractFee(result?.events)!.amount.toBigInt(); + expect(treasuryIncrease, "0% of the fees should go to treasury").to.equal(0n); + + const issuanceDecrease = issuanceBefore - issuanceAfter; + expect((fee * 100n) / issuanceDecrease, "100% of the fees should be burned").to.equal(100n); + }, + }); }, }); From a4493bf3072e7b3990fa4dfc9b0952056ace4133 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Wed, 13 Nov 2024 13:03:55 +0200 Subject: [PATCH 11/26] fix --- .../dev/moonbase/test-parameters/test-parameters-runtime.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts index ad34971daa..409641417e 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts @@ -80,7 +80,7 @@ describeSuite({ const { result } = await context.createBlock( context .polkadotJs() - .tx.balances.transfer(alith.address, 128) + .tx.balances.transferKeepAlive(alith.address, 128) .signAsync(baltathar, { tip: 0 }), { allowFailures: false } ); @@ -122,7 +122,7 @@ describeSuite({ const { result } = await context.createBlock( context .polkadotJs() - .tx.balances.transfer(alith.address, 128) + .tx.balances.transferKeepAlive(alith.address, 128) .signAsync(baltathar, { tip: 128 }), { allowFailures: false } ); From 900f1f09a5c9021940f2a781e7f75406b82c62a0 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Wed, 13 Nov 2024 13:04:58 +0200 Subject: [PATCH 12/26] fix --- .../dev/moonbase/test-parameters/test-parameters-randomness.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts index 526e23d98e..f811d0df99 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-randomness.ts @@ -1,6 +1,5 @@ import { describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; -import { fail } from "assert"; import { parameterType, UNIT } from "./test-parameters"; describeSuite({ From 07d1cde9595e66bbb2e42c9e87729219ef0fcd1f Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Wed, 13 Nov 2024 20:18:50 +0200 Subject: [PATCH 13/26] test: test for different cases --- ...rameters-runtime-FeesTreasuryProportion.ts | 192 ++++++++++++++++++ .../test-parameters-runtime.ts | 144 ------------- 2 files changed, 192 insertions(+), 144 deletions(-) create mode 100644 test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts delete mode 100644 test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts new file mode 100644 index 0000000000..570349bbae --- /dev/null +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts @@ -0,0 +1,192 @@ +import { describeSuite, expect, TransactionTypes } from "@moonwall/cli"; +import { + alith, + baltathar, + BALTATHAR_ADDRESS, + createRawTransfer, + extractFee, + Perbill, + TREASURY_ACCOUNT, +} from "@moonwall/util"; +import { parameterType, UNIT } from "./test-parameters"; +import { BN } from "@polkadot/util"; + +interface TestCase { + proportion: Perbill; + + transfer_amount: bigint; + tipAmount: bigint; +} + +describeSuite({ + id: "DTemp03", + title: "Parameters - RuntimeConfig", + foundationMethods: "dev", + testCases: ({ it, context, log }) => { + let testCounter = 0; + + let testCases: TestCase[] = [ + { + proportion: new Perbill(0), + transfer_amount: 10n * UNIT, + tipAmount: 1n * UNIT, + }, + { + proportion: new Perbill(1, 100), + transfer_amount: 1000n, + tipAmount: 100n, + }, + { + proportion: new Perbill(355, 1000), + transfer_amount: 5n * UNIT, + tipAmount: 111112n, + }, + { + proportion: new Perbill(400, 1000), + transfer_amount: 10n * UNIT, + tipAmount: 1n * UNIT, + }, + { + proportion: new Perbill(500, 1000), + transfer_amount: 10n * UNIT, + tipAmount: 1n * UNIT, + }, + { + proportion: new Perbill(963, 1000), + transfer_amount: 10n * UNIT, + tipAmount: 128n, + }, + { + proportion: new Perbill(99, 100), + transfer_amount: 10n * UNIT, + tipAmount: 3n, + }, + { + proportion: new Perbill(1, 1), + transfer_amount: 10n * UNIT, + tipAmount: 32n, + }, + ]; + + for (const t of testCases) { + const burnProportion = new Perbill(new BN(1e9).sub(t.proportion.value())); + + const treasuryPercentage = t.proportion.value().toNumber() / 1e7; + const burnPercentage = burnProportion.value().toNumber() / 1e7; + + const calcTreasuryIncrease = (feeWithTip: bigint): bigint => { + let val = t.proportion.of(new BN(feeWithTip)); + return BigInt(val.toString()); + }; + const calcIssuanceDecrease = (feeWithTip: bigint): bigint => { + let val = burnProportion.of(new BN(feeWithTip)); + return BigInt(val.toString()); + }; + + for (const txnType of TransactionTypes) { + it({ + id: `T${++testCounter}`, + title: `Changing FeesTreasuryProportion to ${treasuryPercentage}% for Ethereum ${txnType} transfers`, + test: async () => { + const param = parameterType( + context, + "RuntimeConfig", + "FeesTreasuryProportion", + t.proportion.value() + ); + await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a())) + .signAsync(alith), + { allowFailures: false } + ); + + const balBefore = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); + const issuanceBefore = ( + await context.polkadotJs().query.balances.totalIssuance() + ).toBigInt(); + const { result } = await context.createBlock( + await createRawTransfer(context, BALTATHAR_ADDRESS, t.transfer_amount, { + type: txnType, + }) + ); + + const balAfter = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); + const issuanceAfter = ( + await context.polkadotJs().query.balances.totalIssuance() + ).toBigInt(); + + const treasuryIncrease = balAfter - balBefore; + const issuanceDecrease = issuanceBefore - issuanceAfter; + const fee = extractFee(result?.events)!.amount.toBigInt(); + + expect( + treasuryIncrease, + `${treasuryPercentage}% of the fees should go to treasury` + ).to.equal(calcTreasuryIncrease(fee)); + + expect(issuanceDecrease, `${burnPercentage}% of the fees should be burned`).to.equal( + calcIssuanceDecrease(fee) + ); + }, + }); + } + + for (const withTip of [false]) { + it({ + id: `T${++testCounter}`, + title: `Changing FeesTreasuryProportion to ${treasuryPercentage}% for Substrate based transactions with ${ + withTip ? "" : "no " + }tip`, + test: async () => { + const param = parameterType( + context, + "RuntimeConfig", + "FeesTreasuryProportion", + t.proportion.value() + ); + await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a())) + .signAsync(alith), + { allowFailures: false } + ); + + const balanceBefore = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); + const issuanceBefore = ( + await context.polkadotJs().query.balances.totalIssuance() + ).toBigInt(); + + const { result } = await context.createBlock( + context + .polkadotJs() + .tx.balances.transferKeepAlive(alith.address, t.transfer_amount) + .signAsync(baltathar, { tip: withTip ? t.tipAmount : 0n }), + { allowFailures: false } + ); + + const balanceAfter = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); + const issuanceAfter = ( + await context.polkadotJs().query.balances.totalIssuance() + ).toBigInt(); + + const treasuryIncrease = balanceAfter - balanceBefore; + const issuanceDecrease = issuanceBefore - issuanceAfter; + const fee = extractFee(result?.events)!.amount.toBigInt(); + + expect( + treasuryIncrease, + `${treasuryPercentage}% of the fees should go to treasury` + ).to.equal(calcTreasuryIncrease(fee)); + + expect(issuanceDecrease, `${burnPercentage}% of the fees should be burned`).to.equal( + calcIssuanceDecrease(fee) + ); + }, + }); + } + } + }, +}); diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts deleted file mode 100644 index 409641417e..0000000000 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime.ts +++ /dev/null @@ -1,144 +0,0 @@ -import { describeSuite, expect, TransactionTypes } from "@moonwall/cli"; -import { - alith, - baltathar, - BALTATHAR_ADDRESS, - createRawTransfer, - extractFee, - TREASURY_ACCOUNT, -} from "@moonwall/util"; -import { parameterType } from "./test-parameters"; - -describeSuite({ - id: "DTemp02", - title: "Parameters - RuntimeConfig", - foundationMethods: "dev", - testCases: ({ it, context, log }) => { - let testCounter = 0; - - for (const txnType of TransactionTypes) { - it({ - id: `T${++testCounter}`, - title: - `Changing FeesTreasuryProportion to zero should send 0% of fees to treasury for` + - ` Ethereum ${txnType} transfers`, - test: async () => { - const param = parameterType(context, "RuntimeConfig", "FeesTreasuryProportion", 0); - await context.createBlock( - context - .polkadotJs() - .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a())) - .signAsync(alith), - { allowFailures: false } - ); - - const balBefore = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); - const issuanceBefore = ( - await context.polkadotJs().query.balances.totalIssuance() - ).toBigInt(); - const { result } = await context.createBlock( - await createRawTransfer(context, BALTATHAR_ADDRESS, 128, { type: txnType }) - ); - - const balAfter = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); - const issuanceAfter = ( - await context.polkadotJs().query.balances.totalIssuance() - ).toBigInt(); - - const treasuryIncrease = balAfter - balBefore; - const fee = extractFee(result?.events)!.amount.toBigInt(); - expect(treasuryIncrease, "0% of the fees should go to treasury").to.equal(0n); - - const issuanceDecrease = issuanceBefore - issuanceAfter; - expect((fee * 100n) / issuanceDecrease, "100% of the fees should be burned").to.equal( - 100n - ); - }, - }); - } - - it({ - id: `T${++testCounter}`, - title: - `Changing FeesTreasuryProportion to zero should send 0% of fees to treasury for` + - ` Substrate based transactions with no tip`, - test: async () => { - const param = parameterType(context, "RuntimeConfig", "FeesTreasuryProportion", 0); - await context.createBlock( - context - .polkadotJs() - .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a())) - .signAsync(alith), - { allowFailures: false } - ); - - const balanceBefore = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); - const issuanceBefore = ( - await context.polkadotJs().query.balances.totalIssuance() - ).toBigInt(); - - const { result } = await context.createBlock( - context - .polkadotJs() - .tx.balances.transferKeepAlive(alith.address, 128) - .signAsync(baltathar, { tip: 0 }), - { allowFailures: false } - ); - - const balanceAfter = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); - const issuanceAfter = ( - await context.polkadotJs().query.balances.totalIssuance() - ).toBigInt(); - - const treasuryIncrease = balanceAfter - balanceBefore; - const fee = extractFee(result?.events)!.amount.toBigInt(); - expect(treasuryIncrease, "0% of the fees should go to treasury").to.equal(0n); - - const issuanceDecrease = issuanceBefore - issuanceAfter; - expect((fee * 100n) / issuanceDecrease, "100% of the fees should be burned").to.equal(100n); - }, - }); - - it({ - id: `T${++testCounter}`, - title: - `Changing FeesTreasuryProportion to zero should send 0% of fees to treasury for` + - ` Substrate based transactions with tip`, - test: async () => { - const param = parameterType(context, "RuntimeConfig", "FeesTreasuryProportion", 0); - await context.createBlock( - context - .polkadotJs() - .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a())) - .signAsync(alith), - { allowFailures: false } - ); - - const balanceBefore = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); - const issuanceBefore = ( - await context.polkadotJs().query.balances.totalIssuance() - ).toBigInt(); - - const { result } = await context.createBlock( - context - .polkadotJs() - .tx.balances.transferKeepAlive(alith.address, 128) - .signAsync(baltathar, { tip: 128 }), - { allowFailures: false } - ); - - const balanceAfter = await context.viem().getBalance({ address: TREASURY_ACCOUNT }); - const issuanceAfter = ( - await context.polkadotJs().query.balances.totalIssuance() - ).toBigInt(); - - const treasuryIncrease = balanceAfter - balanceBefore; - const fee = extractFee(result?.events)!.amount.toBigInt(); - expect(treasuryIncrease, "0% of the fees should go to treasury").to.equal(0n); - - const issuanceDecrease = issuanceBefore - issuanceAfter; - expect((fee * 100n) / issuanceDecrease, "100% of the fees should be burned").to.equal(100n); - }, - }); - }, -}); From 536b329b09a3fc0e3c98bf5860dce30ca5aacbbb Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Wed, 13 Nov 2024 20:37:23 +0200 Subject: [PATCH 14/26] test: add extra check --- ...-parameters-runtime-FeesTreasuryProportion.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts index 570349bbae..66aa76fec7 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts @@ -25,7 +25,7 @@ describeSuite({ testCases: ({ it, context, log }) => { let testCounter = 0; - let testCases: TestCase[] = [ + const testCases: TestCase[] = [ { proportion: new Perbill(0), transfer_amount: 10n * UNIT, @@ -75,11 +75,11 @@ describeSuite({ const burnPercentage = burnProportion.value().toNumber() / 1e7; const calcTreasuryIncrease = (feeWithTip: bigint): bigint => { - let val = t.proportion.of(new BN(feeWithTip)); + const val = t.proportion.of(new BN(feeWithTip)); return BigInt(val.toString()); }; const calcIssuanceDecrease = (feeWithTip: bigint): bigint => { - let val = burnProportion.of(new BN(feeWithTip)); + const val = burnProportion.of(new BN(feeWithTip)); return BigInt(val.toString()); }; @@ -121,6 +121,11 @@ describeSuite({ const issuanceDecrease = issuanceBefore - issuanceAfter; const fee = extractFee(result?.events)!.amount.toBigInt(); + expect( + treasuryIncrease + issuanceDecrease, + `Sum of TreasuryIncrease and IssuanceDecrease should be equal to the fees` + ).to.equal(fee); + expect( treasuryIncrease, `${treasuryPercentage}% of the fees should go to treasury` @@ -176,6 +181,11 @@ describeSuite({ const issuanceDecrease = issuanceBefore - issuanceAfter; const fee = extractFee(result?.events)!.amount.toBigInt(); + expect( + treasuryIncrease + issuanceDecrease, + `Sum of TreasuryIncrease and IssuanceDecrease should be equal to the fees` + ).to.equal(fee); + expect( treasuryIncrease, `${treasuryPercentage}% of the fees should go to treasury` From 30b46cdcb8c50d753d2c13032d41747cfe69aaca Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Wed, 13 Nov 2024 21:22:50 +0200 Subject: [PATCH 15/26] fix: test calculation --- ...arameters-runtime-FeesTreasuryProportion.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts index 66aa76fec7..560038b68f 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts @@ -75,18 +75,22 @@ describeSuite({ const burnPercentage = burnProportion.value().toNumber() / 1e7; const calcTreasuryIncrease = (feeWithTip: bigint): bigint => { - const val = t.proportion.of(new BN(feeWithTip)); + const feeWithTipBN = new BN(feeWithTip.toString()); + const proportion: BN = t.proportion.value(); + const val = feeWithTipBN.mul(proportion).div(new BN(1e9)); return BigInt(val.toString()); }; const calcIssuanceDecrease = (feeWithTip: bigint): bigint => { - const val = burnProportion.of(new BN(feeWithTip)); - return BigInt(val.toString()); + const treasuryIncrease = calcTreasuryIncrease(feeWithTip); + return feeWithTip - treasuryIncrease; }; for (const txnType of TransactionTypes) { it({ id: `T${++testCounter}`, - title: `Changing FeesTreasuryProportion to ${treasuryPercentage}% for Ethereum ${txnType} transfers`, + title: + `Changing FeesTreasuryProportion to ${treasuryPercentage}% for Ethereum` + + `${txnType} transfers`, test: async () => { const param = parameterType( context, @@ -141,9 +145,9 @@ describeSuite({ for (const withTip of [false]) { it({ id: `T${++testCounter}`, - title: `Changing FeesTreasuryProportion to ${treasuryPercentage}% for Substrate based transactions with ${ - withTip ? "" : "no " - }tip`, + title: + `Changing FeesTreasuryProportion to ${treasuryPercentage}% for Substrate based` + + `transactions with ${withTip ? "" : "no "}tip`, test: async () => { const param = parameterType( context, From 6eade28e62f40826f92b80d5658f2eea9a360965 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 14 Nov 2024 12:26:32 +0200 Subject: [PATCH 16/26] fix: test calculation --- runtime/moonbase/src/lib.rs | 54 ++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 7c699860f6..acaa397e3f 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -361,14 +361,14 @@ where { // this seems to be called for substrate-based transactions fn on_unbalanceds( - mut fees_then_tips: impl Iterator>>, + mut fees_then_tips: impl Iterator>>, ) { if let Some(fees) = fees_then_tips.next() { let treasury_proportion = runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); let treasury_part = treasury_proportion.deconstruct(); let burn_part = Perbill::one().deconstruct() - treasury_part; - let (_, to_treasury) = fees.ration(burn_part, treasury_part); + let (to_treasury, _) = fees.ration(treasury_part, burn_part); // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly ResolveTo::, pallet_balances::Pallet>::on_unbalanced( @@ -378,7 +378,7 @@ where // handle tip if there is one if let Some(tip) = fees_then_tips.next() { // for now we use the same burn/treasury strategy used for regular fees - let (_, to_treasury) = tip.ration(burn_part, treasury_part); + let (to_treasury, _) = tip.ration(treasury_part, burn_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced( to_treasury, ); @@ -395,7 +395,7 @@ where runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); let treasury_part = treasury_proportion.deconstruct(); let burn_part = Perbill::one().deconstruct() - treasury_part; - let (_, to_treasury) = amount.ration(burn_part, treasury_part); + let (to_treasury, _) = amount.ration(treasury_part, burn_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced(to_treasury); } } @@ -536,7 +536,7 @@ where { fn find_author<'a, I>(digests: I) -> Option where - I: 'a + IntoIterator, + I: 'a + IntoIterator, { Inner::find_author(digests).map(Into::into) } @@ -634,7 +634,7 @@ impl pallet_treasury::Config for Runtime { type SpendOrigin = frame_support::traits::NeverEnsureOrigin; // Disabled, no spending #[cfg(feature = "runtime-benchmarks")] type SpendOrigin = - frame_system::EnsureWithSuccess, AccountId, benches::MaxBalance>; + frame_system::EnsureWithSuccess, AccountId, benches::MaxBalance>; type AssetKind = (); type Beneficiary = AccountId; type BeneficiaryLookup = IdentityLookup; @@ -655,9 +655,9 @@ parameter_types! { } type IdentityForceOrigin = - EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +EitherOfDiverse, governance::custom_origins::GeneralAdmin>; type IdentityRegistrarOrigin = - EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +EitherOfDiverse, governance::custom_origins::GeneralAdmin>; impl pallet_identity::Config for Runtime { type RuntimeEvent = RuntimeEvent; @@ -728,7 +728,7 @@ impl xcm_primitives::EnsureProxy for EthereumXcmEnsureProxy { &delegatee, Some(ProxyType::Any), ) - .map_err(|_| "proxy error: expected `ProxyType::Any`")?; + .map_err(|_| "proxy error: expected `ProxyType::Any`")?; // We only allow to use it for delay zero proxies, as the call will immediatly be executed ensure!(def.delay.is_zero(), "proxy delay is Non-zero`"); Ok(()) @@ -832,7 +832,7 @@ impl pallet_parachain_staking::OnInactiveCollator for OnInactiveCollato } type MonetaryGovernanceOrigin = - EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +EitherOfDiverse, governance::custom_origins::GeneralAdmin>; pub struct RelayChainSlotProvider; impl Get for RelayChainSlotProvider { @@ -1022,14 +1022,14 @@ impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType { ProxyType::NonTransfer => { call.value == U256::zero() && match PrecompileName::from_address(call.to.0) { - Some( - PrecompileName::AuthorMappingPrecompile - | PrecompileName::IdentityPrecompile - | PrecompileName::ParachainStakingPrecompile, - ) => true, - Some(ref precompile) if is_governance_precompile(precompile) => true, - _ => false, - } + Some( + PrecompileName::AuthorMappingPrecompile + | PrecompileName::IdentityPrecompile + | PrecompileName::ParachainStakingPrecompile, + ) => true, + Some(ref precompile) if is_governance_precompile(precompile) => true, + _ => false, + } } ProxyType::Governance => { call.value == U256::zero() @@ -1056,8 +1056,8 @@ impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType { // have no code. !recipient_has_code && !precompile_utils::precompile_set::is_precompile_or_fail::( - call.to.0, gas, - )? + call.to.0, gas, + )? } ProxyType::AuthorMapping => { call.value == U256::zero() @@ -1259,7 +1259,7 @@ impl pallet_maintenance_mode::Config for Runtime { type NormalCallFilter = NormalFilter; type MaintenanceCallFilter = MaintenanceFilter; type MaintenanceOrigin = - pallet_collective::EnsureProportionAtLeast; + pallet_collective::EnsureProportionAtLeast; type XcmExecutionManager = XcmExecutionManager; } @@ -1272,9 +1272,9 @@ parameter_types! { } type AddCollatorOrigin = - EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +EitherOfDiverse, governance::custom_origins::GeneralAdmin>; type DelCollatorOrigin = - EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +EitherOfDiverse, governance::custom_origins::GeneralAdmin>; impl pallet_moonbeam_orbiters::Config for Runtime { type RuntimeEvent = RuntimeEvent; @@ -1485,10 +1485,10 @@ pub type SignedExtra = ( ); /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = - fp_self_contained::UncheckedExtrinsic; +fp_self_contained::UncheckedExtrinsic; /// Extrinsic type that has already been checked. pub type CheckedExtrinsic = - fp_self_contained::CheckedExtrinsic; +fp_self_contained::CheckedExtrinsic; /// Executive: handles dispatch to the various pallets. pub type Executive = frame_executive::Executive< Runtime, @@ -1649,8 +1649,8 @@ impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { relay_chain_slot, sp_std::time::Duration::from_secs(6), ) - .create_inherent_data() - .expect("Could not create the timestamp inherent data"); + .create_inherent_data() + .expect("Could not create the timestamp inherent data"); inherent_data.check_extrinsics(block) } } From ef2d73edc2975919c84aab0dcde7c2ab3ec87883 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 14 Nov 2024 13:09:35 +0200 Subject: [PATCH 17/26] style: fix formatting --- runtime/moonbase/src/lib.rs | 48 ++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index acaa397e3f..0492f91ffe 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -361,7 +361,7 @@ where { // this seems to be called for substrate-based transactions fn on_unbalanceds( - mut fees_then_tips: impl Iterator>>, + mut fees_then_tips: impl Iterator>>, ) { if let Some(fees) = fees_then_tips.next() { let treasury_proportion = @@ -536,7 +536,7 @@ where { fn find_author<'a, I>(digests: I) -> Option where - I: 'a + IntoIterator, + I: 'a + IntoIterator, { Inner::find_author(digests).map(Into::into) } @@ -634,7 +634,7 @@ impl pallet_treasury::Config for Runtime { type SpendOrigin = frame_support::traits::NeverEnsureOrigin; // Disabled, no spending #[cfg(feature = "runtime-benchmarks")] type SpendOrigin = - frame_system::EnsureWithSuccess, AccountId, benches::MaxBalance>; + frame_system::EnsureWithSuccess, AccountId, benches::MaxBalance>; type AssetKind = (); type Beneficiary = AccountId; type BeneficiaryLookup = IdentityLookup; @@ -655,9 +655,9 @@ parameter_types! { } type IdentityForceOrigin = -EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; type IdentityRegistrarOrigin = -EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; impl pallet_identity::Config for Runtime { type RuntimeEvent = RuntimeEvent; @@ -728,7 +728,7 @@ impl xcm_primitives::EnsureProxy for EthereumXcmEnsureProxy { &delegatee, Some(ProxyType::Any), ) - .map_err(|_| "proxy error: expected `ProxyType::Any`")?; + .map_err(|_| "proxy error: expected `ProxyType::Any`")?; // We only allow to use it for delay zero proxies, as the call will immediatly be executed ensure!(def.delay.is_zero(), "proxy delay is Non-zero`"); Ok(()) @@ -832,7 +832,7 @@ impl pallet_parachain_staking::OnInactiveCollator for OnInactiveCollato } type MonetaryGovernanceOrigin = -EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; pub struct RelayChainSlotProvider; impl Get for RelayChainSlotProvider { @@ -1022,14 +1022,14 @@ impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType { ProxyType::NonTransfer => { call.value == U256::zero() && match PrecompileName::from_address(call.to.0) { - Some( - PrecompileName::AuthorMappingPrecompile - | PrecompileName::IdentityPrecompile - | PrecompileName::ParachainStakingPrecompile, - ) => true, - Some(ref precompile) if is_governance_precompile(precompile) => true, - _ => false, - } + Some( + PrecompileName::AuthorMappingPrecompile + | PrecompileName::IdentityPrecompile + | PrecompileName::ParachainStakingPrecompile, + ) => true, + Some(ref precompile) if is_governance_precompile(precompile) => true, + _ => false, + } } ProxyType::Governance => { call.value == U256::zero() @@ -1056,8 +1056,8 @@ impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType { // have no code. !recipient_has_code && !precompile_utils::precompile_set::is_precompile_or_fail::( - call.to.0, gas, - )? + call.to.0, gas, + )? } ProxyType::AuthorMapping => { call.value == U256::zero() @@ -1259,7 +1259,7 @@ impl pallet_maintenance_mode::Config for Runtime { type NormalCallFilter = NormalFilter; type MaintenanceCallFilter = MaintenanceFilter; type MaintenanceOrigin = - pallet_collective::EnsureProportionAtLeast; + pallet_collective::EnsureProportionAtLeast; type XcmExecutionManager = XcmExecutionManager; } @@ -1272,9 +1272,9 @@ parameter_types! { } type AddCollatorOrigin = -EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; type DelCollatorOrigin = -EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; impl pallet_moonbeam_orbiters::Config for Runtime { type RuntimeEvent = RuntimeEvent; @@ -1485,10 +1485,10 @@ pub type SignedExtra = ( ); /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = -fp_self_contained::UncheckedExtrinsic; + fp_self_contained::UncheckedExtrinsic; /// Extrinsic type that has already been checked. pub type CheckedExtrinsic = -fp_self_contained::CheckedExtrinsic; + fp_self_contained::CheckedExtrinsic; /// Executive: handles dispatch to the various pallets. pub type Executive = frame_executive::Executive< Runtime, @@ -1649,8 +1649,8 @@ impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { relay_chain_slot, sp_std::time::Duration::from_secs(6), ) - .create_inherent_data() - .expect("Could not create the timestamp inherent data"); + .create_inherent_data() + .expect("Could not create the timestamp inherent data"); inherent_data.check_extrinsics(block) } } From f63a803709886a45d6fb5700164c4b6114a887ee Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 14 Nov 2024 13:13:42 +0200 Subject: [PATCH 18/26] fix: fix calculation for moonriver and moonbeam --- runtime/moonbeam/src/lib.rs | 6 +++--- runtime/moonriver/src/lib.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 91635966c5..34473f197d 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -356,7 +356,7 @@ where runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); let treasury_part = treasury_proportion.deconstruct(); let burn_part = Perbill::one().deconstruct() - treasury_part; - let (_, to_treasury) = fees.ration(burn_part, treasury_part); + let (to_treasury, _) = fees.ration(treasury_part, burn_part); // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly ResolveTo::, pallet_balances::Pallet>::on_unbalanced( @@ -366,7 +366,7 @@ where // handle tip if there is one if let Some(tip) = fees_then_tips.next() { // for now we use the same burn/treasury strategy used for regular fees - let (_, to_treasury) = tip.ration(burn_part, treasury_part); + let (to_treasury, _) = tip.ration(treasury_part, burn_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced( to_treasury, ); @@ -383,7 +383,7 @@ where runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); let treasury_part = treasury_proportion.deconstruct(); let burn_part = Perbill::one().deconstruct() - treasury_part; - let (_, to_treasury) = amount.ration(burn_part, treasury_part); + let (to_treasury, _) = amount.ration(treasury_part, burn_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced(to_treasury); } } diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index bd9776892e..8e46af40be 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -358,7 +358,7 @@ where runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); let treasury_part = treasury_proportion.deconstruct(); let burn_part = Perbill::one().deconstruct() - treasury_part; - let (_, to_treasury) = fees.ration(burn_part, treasury_part); + let (to_treasury, _) = fees.ration(treasury_part, burn_part); // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly ResolveTo::, pallet_balances::Pallet>::on_unbalanced( @@ -368,7 +368,7 @@ where // handle tip if there is one if let Some(tip) = fees_then_tips.next() { // for now we use the same burn/treasury strategy used for regular fees - let (_, to_treasury) = tip.ration(burn_part, treasury_part); + let (to_treasury, _) = tip.ration(treasury_part, burn_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced( to_treasury, ); @@ -385,7 +385,7 @@ where runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); let treasury_part = treasury_proportion.deconstruct(); let burn_part = Perbill::one().deconstruct() - treasury_part; - let (_, to_treasury) = amount.ration(burn_part, treasury_part); + let (to_treasury, _) = amount.ration(treasury_part, burn_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced(to_treasury); } } From 0531166bb15869b13ac9234599024c1f67b5c0a1 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 14 Nov 2024 13:31:02 +0200 Subject: [PATCH 19/26] Revert "fix: fix calculation for moonriver and moonbeam" This reverts commit f63a803709886a45d6fb5700164c4b6114a887ee. --- runtime/moonbeam/src/lib.rs | 6 +++--- runtime/moonriver/src/lib.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 34473f197d..91635966c5 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -356,7 +356,7 @@ where runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); let treasury_part = treasury_proportion.deconstruct(); let burn_part = Perbill::one().deconstruct() - treasury_part; - let (to_treasury, _) = fees.ration(treasury_part, burn_part); + let (_, to_treasury) = fees.ration(burn_part, treasury_part); // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly ResolveTo::, pallet_balances::Pallet>::on_unbalanced( @@ -366,7 +366,7 @@ where // handle tip if there is one if let Some(tip) = fees_then_tips.next() { // for now we use the same burn/treasury strategy used for regular fees - let (to_treasury, _) = tip.ration(treasury_part, burn_part); + let (_, to_treasury) = tip.ration(burn_part, treasury_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced( to_treasury, ); @@ -383,7 +383,7 @@ where runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); let treasury_part = treasury_proportion.deconstruct(); let burn_part = Perbill::one().deconstruct() - treasury_part; - let (to_treasury, _) = amount.ration(treasury_part, burn_part); + let (_, to_treasury) = amount.ration(burn_part, treasury_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced(to_treasury); } } diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 8e46af40be..bd9776892e 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -358,7 +358,7 @@ where runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); let treasury_part = treasury_proportion.deconstruct(); let burn_part = Perbill::one().deconstruct() - treasury_part; - let (to_treasury, _) = fees.ration(treasury_part, burn_part); + let (_, to_treasury) = fees.ration(burn_part, treasury_part); // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly ResolveTo::, pallet_balances::Pallet>::on_unbalanced( @@ -368,7 +368,7 @@ where // handle tip if there is one if let Some(tip) = fees_then_tips.next() { // for now we use the same burn/treasury strategy used for regular fees - let (to_treasury, _) = tip.ration(treasury_part, burn_part); + let (_, to_treasury) = tip.ration(burn_part, treasury_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced( to_treasury, ); @@ -385,7 +385,7 @@ where runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); let treasury_part = treasury_proportion.deconstruct(); let burn_part = Perbill::one().deconstruct() - treasury_part; - let (to_treasury, _) = amount.ration(treasury_part, burn_part); + let (_, to_treasury) = amount.ration(burn_part, treasury_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced(to_treasury); } } From cf1276ee16efc5d0b849d70a4f54a3d4bb3a7e42 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 14 Nov 2024 13:31:02 +0200 Subject: [PATCH 20/26] Revert "style: fix formatting" This reverts commit ef2d73edc2975919c84aab0dcde7c2ab3ec87883. --- runtime/moonbase/src/lib.rs | 48 ++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 0492f91ffe..acaa397e3f 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -361,7 +361,7 @@ where { // this seems to be called for substrate-based transactions fn on_unbalanceds( - mut fees_then_tips: impl Iterator>>, + mut fees_then_tips: impl Iterator>>, ) { if let Some(fees) = fees_then_tips.next() { let treasury_proportion = @@ -536,7 +536,7 @@ where { fn find_author<'a, I>(digests: I) -> Option where - I: 'a + IntoIterator, + I: 'a + IntoIterator, { Inner::find_author(digests).map(Into::into) } @@ -634,7 +634,7 @@ impl pallet_treasury::Config for Runtime { type SpendOrigin = frame_support::traits::NeverEnsureOrigin; // Disabled, no spending #[cfg(feature = "runtime-benchmarks")] type SpendOrigin = - frame_system::EnsureWithSuccess, AccountId, benches::MaxBalance>; + frame_system::EnsureWithSuccess, AccountId, benches::MaxBalance>; type AssetKind = (); type Beneficiary = AccountId; type BeneficiaryLookup = IdentityLookup; @@ -655,9 +655,9 @@ parameter_types! { } type IdentityForceOrigin = - EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +EitherOfDiverse, governance::custom_origins::GeneralAdmin>; type IdentityRegistrarOrigin = - EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +EitherOfDiverse, governance::custom_origins::GeneralAdmin>; impl pallet_identity::Config for Runtime { type RuntimeEvent = RuntimeEvent; @@ -728,7 +728,7 @@ impl xcm_primitives::EnsureProxy for EthereumXcmEnsureProxy { &delegatee, Some(ProxyType::Any), ) - .map_err(|_| "proxy error: expected `ProxyType::Any`")?; + .map_err(|_| "proxy error: expected `ProxyType::Any`")?; // We only allow to use it for delay zero proxies, as the call will immediatly be executed ensure!(def.delay.is_zero(), "proxy delay is Non-zero`"); Ok(()) @@ -832,7 +832,7 @@ impl pallet_parachain_staking::OnInactiveCollator for OnInactiveCollato } type MonetaryGovernanceOrigin = - EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +EitherOfDiverse, governance::custom_origins::GeneralAdmin>; pub struct RelayChainSlotProvider; impl Get for RelayChainSlotProvider { @@ -1022,14 +1022,14 @@ impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType { ProxyType::NonTransfer => { call.value == U256::zero() && match PrecompileName::from_address(call.to.0) { - Some( - PrecompileName::AuthorMappingPrecompile - | PrecompileName::IdentityPrecompile - | PrecompileName::ParachainStakingPrecompile, - ) => true, - Some(ref precompile) if is_governance_precompile(precompile) => true, - _ => false, - } + Some( + PrecompileName::AuthorMappingPrecompile + | PrecompileName::IdentityPrecompile + | PrecompileName::ParachainStakingPrecompile, + ) => true, + Some(ref precompile) if is_governance_precompile(precompile) => true, + _ => false, + } } ProxyType::Governance => { call.value == U256::zero() @@ -1056,8 +1056,8 @@ impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType { // have no code. !recipient_has_code && !precompile_utils::precompile_set::is_precompile_or_fail::( - call.to.0, gas, - )? + call.to.0, gas, + )? } ProxyType::AuthorMapping => { call.value == U256::zero() @@ -1259,7 +1259,7 @@ impl pallet_maintenance_mode::Config for Runtime { type NormalCallFilter = NormalFilter; type MaintenanceCallFilter = MaintenanceFilter; type MaintenanceOrigin = - pallet_collective::EnsureProportionAtLeast; + pallet_collective::EnsureProportionAtLeast; type XcmExecutionManager = XcmExecutionManager; } @@ -1272,9 +1272,9 @@ parameter_types! { } type AddCollatorOrigin = - EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +EitherOfDiverse, governance::custom_origins::GeneralAdmin>; type DelCollatorOrigin = - EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +EitherOfDiverse, governance::custom_origins::GeneralAdmin>; impl pallet_moonbeam_orbiters::Config for Runtime { type RuntimeEvent = RuntimeEvent; @@ -1485,10 +1485,10 @@ pub type SignedExtra = ( ); /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = - fp_self_contained::UncheckedExtrinsic; +fp_self_contained::UncheckedExtrinsic; /// Extrinsic type that has already been checked. pub type CheckedExtrinsic = - fp_self_contained::CheckedExtrinsic; +fp_self_contained::CheckedExtrinsic; /// Executive: handles dispatch to the various pallets. pub type Executive = frame_executive::Executive< Runtime, @@ -1649,8 +1649,8 @@ impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { relay_chain_slot, sp_std::time::Duration::from_secs(6), ) - .create_inherent_data() - .expect("Could not create the timestamp inherent data"); + .create_inherent_data() + .expect("Could not create the timestamp inherent data"); inherent_data.check_extrinsics(block) } } From 6140e3ce6c88ecbe1b43fed706fbd4d8272cda27 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 14 Nov 2024 13:31:02 +0200 Subject: [PATCH 21/26] Revert "fix: test calculation" This reverts commit 6eade28e62f40826f92b80d5658f2eea9a360965. --- runtime/moonbase/src/lib.rs | 54 ++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index acaa397e3f..7c699860f6 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -361,14 +361,14 @@ where { // this seems to be called for substrate-based transactions fn on_unbalanceds( - mut fees_then_tips: impl Iterator>>, + mut fees_then_tips: impl Iterator>>, ) { if let Some(fees) = fees_then_tips.next() { let treasury_proportion = runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); let treasury_part = treasury_proportion.deconstruct(); let burn_part = Perbill::one().deconstruct() - treasury_part; - let (to_treasury, _) = fees.ration(treasury_part, burn_part); + let (_, to_treasury) = fees.ration(burn_part, treasury_part); // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly ResolveTo::, pallet_balances::Pallet>::on_unbalanced( @@ -378,7 +378,7 @@ where // handle tip if there is one if let Some(tip) = fees_then_tips.next() { // for now we use the same burn/treasury strategy used for regular fees - let (to_treasury, _) = tip.ration(treasury_part, burn_part); + let (_, to_treasury) = tip.ration(burn_part, treasury_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced( to_treasury, ); @@ -395,7 +395,7 @@ where runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); let treasury_part = treasury_proportion.deconstruct(); let burn_part = Perbill::one().deconstruct() - treasury_part; - let (to_treasury, _) = amount.ration(treasury_part, burn_part); + let (_, to_treasury) = amount.ration(burn_part, treasury_part); ResolveTo::, pallet_balances::Pallet>::on_unbalanced(to_treasury); } } @@ -536,7 +536,7 @@ where { fn find_author<'a, I>(digests: I) -> Option where - I: 'a + IntoIterator, + I: 'a + IntoIterator, { Inner::find_author(digests).map(Into::into) } @@ -634,7 +634,7 @@ impl pallet_treasury::Config for Runtime { type SpendOrigin = frame_support::traits::NeverEnsureOrigin; // Disabled, no spending #[cfg(feature = "runtime-benchmarks")] type SpendOrigin = - frame_system::EnsureWithSuccess, AccountId, benches::MaxBalance>; + frame_system::EnsureWithSuccess, AccountId, benches::MaxBalance>; type AssetKind = (); type Beneficiary = AccountId; type BeneficiaryLookup = IdentityLookup; @@ -655,9 +655,9 @@ parameter_types! { } type IdentityForceOrigin = -EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; type IdentityRegistrarOrigin = -EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; impl pallet_identity::Config for Runtime { type RuntimeEvent = RuntimeEvent; @@ -728,7 +728,7 @@ impl xcm_primitives::EnsureProxy for EthereumXcmEnsureProxy { &delegatee, Some(ProxyType::Any), ) - .map_err(|_| "proxy error: expected `ProxyType::Any`")?; + .map_err(|_| "proxy error: expected `ProxyType::Any`")?; // We only allow to use it for delay zero proxies, as the call will immediatly be executed ensure!(def.delay.is_zero(), "proxy delay is Non-zero`"); Ok(()) @@ -832,7 +832,7 @@ impl pallet_parachain_staking::OnInactiveCollator for OnInactiveCollato } type MonetaryGovernanceOrigin = -EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; pub struct RelayChainSlotProvider; impl Get for RelayChainSlotProvider { @@ -1022,14 +1022,14 @@ impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType { ProxyType::NonTransfer => { call.value == U256::zero() && match PrecompileName::from_address(call.to.0) { - Some( - PrecompileName::AuthorMappingPrecompile - | PrecompileName::IdentityPrecompile - | PrecompileName::ParachainStakingPrecompile, - ) => true, - Some(ref precompile) if is_governance_precompile(precompile) => true, - _ => false, - } + Some( + PrecompileName::AuthorMappingPrecompile + | PrecompileName::IdentityPrecompile + | PrecompileName::ParachainStakingPrecompile, + ) => true, + Some(ref precompile) if is_governance_precompile(precompile) => true, + _ => false, + } } ProxyType::Governance => { call.value == U256::zero() @@ -1056,8 +1056,8 @@ impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType { // have no code. !recipient_has_code && !precompile_utils::precompile_set::is_precompile_or_fail::( - call.to.0, gas, - )? + call.to.0, gas, + )? } ProxyType::AuthorMapping => { call.value == U256::zero() @@ -1259,7 +1259,7 @@ impl pallet_maintenance_mode::Config for Runtime { type NormalCallFilter = NormalFilter; type MaintenanceCallFilter = MaintenanceFilter; type MaintenanceOrigin = - pallet_collective::EnsureProportionAtLeast; + pallet_collective::EnsureProportionAtLeast; type XcmExecutionManager = XcmExecutionManager; } @@ -1272,9 +1272,9 @@ parameter_types! { } type AddCollatorOrigin = -EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; type DelCollatorOrigin = -EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; impl pallet_moonbeam_orbiters::Config for Runtime { type RuntimeEvent = RuntimeEvent; @@ -1485,10 +1485,10 @@ pub type SignedExtra = ( ); /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = -fp_self_contained::UncheckedExtrinsic; + fp_self_contained::UncheckedExtrinsic; /// Extrinsic type that has already been checked. pub type CheckedExtrinsic = -fp_self_contained::CheckedExtrinsic; + fp_self_contained::CheckedExtrinsic; /// Executive: handles dispatch to the various pallets. pub type Executive = frame_executive::Executive< Runtime, @@ -1649,8 +1649,8 @@ impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { relay_chain_slot, sp_std::time::Duration::from_secs(6), ) - .create_inherent_data() - .expect("Could not create the timestamp inherent data"); + .create_inherent_data() + .expect("Could not create the timestamp inherent data"); inherent_data.check_extrinsics(block) } } From 8c01ec5ca96a2210780e7a04e1a1e749715f8a48 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 14 Nov 2024 13:33:54 +0200 Subject: [PATCH 22/26] fix: fix calculation --- ...test-parameters-runtime-FeesTreasuryProportion.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts index 560038b68f..1e147b82c8 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts @@ -75,15 +75,17 @@ describeSuite({ const burnPercentage = burnProportion.value().toNumber() / 1e7; const calcTreasuryIncrease = (feeWithTip: bigint): bigint => { + // In rust code fees.ration(treasury_part, burn_part) + // treasury increase is being calculated this way + const issuanceDecrease = calcIssuanceDecrease(feeWithTip); + return feeWithTip - issuanceDecrease; + }; + const calcIssuanceDecrease = (feeWithTip: bigint): bigint => { const feeWithTipBN = new BN(feeWithTip.toString()); - const proportion: BN = t.proportion.value(); + const proportion: BN = burnProportion.value(); const val = feeWithTipBN.mul(proportion).div(new BN(1e9)); return BigInt(val.toString()); }; - const calcIssuanceDecrease = (feeWithTip: bigint): bigint => { - const treasuryIncrease = calcTreasuryIncrease(feeWithTip); - return feeWithTip - treasuryIncrease; - }; for (const txnType of TransactionTypes) { it({ From 76f1e2459b5515a5d26cfd8a043dc0ed720bbe35 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 14 Nov 2024 16:30:58 +0200 Subject: [PATCH 23/26] test: add with tip case --- .../test-parameters-runtime-FeesTreasuryProportion.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts index 1e147b82c8..c770cceeb4 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts @@ -144,7 +144,7 @@ describeSuite({ }); } - for (const withTip of [false]) { + for (const withTip of [false, true]) { it({ id: `T${++testCounter}`, title: From 59ba104a85197c22bb888f001eae5f09911cc7cd Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 14 Nov 2024 18:13:50 +0200 Subject: [PATCH 24/26] test: fix calc --- ...rameters-runtime-FeesTreasuryProportion.ts | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts index c770cceeb4..d6cd10d1ec 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts @@ -74,17 +74,34 @@ describeSuite({ const treasuryPercentage = t.proportion.value().toNumber() / 1e7; const burnPercentage = burnProportion.value().toNumber() / 1e7; - const calcTreasuryIncrease = (feeWithTip: bigint): bigint => { - // In rust code fees.ration(treasury_part, burn_part) - // treasury increase is being calculated this way - const issuanceDecrease = calcIssuanceDecrease(feeWithTip); + // Recreation on fees.ration(burn_part, treasury_part) + const split = (value: BN, part1: BN, part2: BN): [BN, BN] => { + const total = part1.add(part2); + if (total.eq(new BN(0)) || value.eq(new BN(0))) { + return [new BN(0), new BN(0)]; + } + const part1BN = value.mul(part1).div(total); + const part2BN = value.sub(part1BN); + return [part1BN, part2BN]; + }; + + const calcTreasuryIncrease = (feeWithTip: bigint, tip?: bigint): bigint => { + const issuanceDecrease = calcIssuanceDecrease(feeWithTip, tip); return feeWithTip - issuanceDecrease; }; - const calcIssuanceDecrease = (feeWithTip: bigint): bigint => { + const calcIssuanceDecrease = (feeWithTip: bigint, tip?: bigint): bigint => { const feeWithTipBN = new BN(feeWithTip.toString()); - const proportion: BN = burnProportion.value(); - const val = feeWithTipBN.mul(proportion).div(new BN(1e9)); - return BigInt(val.toString()); + const tipBN = new BN(tip?.toString() || "0"); + const feeWithoutTipBN = feeWithTipBN.sub(tipBN); + + const [_, burnFeePart] = split( + feeWithoutTipBN, + burnProportion.value(), + t.proportion.value() + ); + const [_, burnTipPart] = split(tipBN, burnProportion.value(), t.proportion.value()); + + return BigInt(burnFeePart.add(burnTipPart).toString()); }; for (const txnType of TransactionTypes) { @@ -195,10 +212,10 @@ describeSuite({ expect( treasuryIncrease, `${treasuryPercentage}% of the fees should go to treasury` - ).to.equal(calcTreasuryIncrease(fee)); + ).to.equal(calcTreasuryIncrease(fee, withTip ? t.tipAmount : undefined)); expect(issuanceDecrease, `${burnPercentage}% of the fees should be burned`).to.equal( - calcIssuanceDecrease(fee) + calcIssuanceDecrease(fee, withTip ? t.tipAmount : undefined) ); }, }); From 1c33c7a89cab7a3156da63c69b2179e7c25b914c Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 14 Nov 2024 18:36:22 +0200 Subject: [PATCH 25/26] test: fix calc --- .../test-parameters-runtime-FeesTreasuryProportion.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts index d6cd10d1ec..cfc739069f 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts @@ -99,7 +99,7 @@ describeSuite({ burnProportion.value(), t.proportion.value() ); - const [_, burnTipPart] = split(tipBN, burnProportion.value(), t.proportion.value()); + const [__, burnTipPart] = split(tipBN, burnProportion.value(), t.proportion.value()); return BigInt(burnFeePart.add(burnTipPart).toString()); }; From 89591e6d98055a1569e5af45089d2715db16a3bd Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 14 Nov 2024 21:21:00 +0200 Subject: [PATCH 26/26] test: fix calc --- ...rameters-runtime-FeesTreasuryProportion.ts | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts index cfc739069f..bd10311cc8 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters-runtime-FeesTreasuryProportion.ts @@ -18,6 +18,17 @@ interface TestCase { tipAmount: bigint; } +// Recreation on fees.ration(burn_part, treasury_part) +const split = (value: BN, part1: BN, part2: BN): [BN, BN] => { + const total = part1.add(part2); + if (total.eq(new BN(0)) || value.eq(new BN(0))) { + return [new BN(0), new BN(0)]; + } + const part1BN = value.mul(part1).div(total); + const part2BN = value.sub(part1BN); + return [part1BN, part2BN]; +}; + describeSuite({ id: "DTemp03", title: "Parameters - RuntimeConfig", @@ -74,32 +85,38 @@ describeSuite({ const treasuryPercentage = t.proportion.value().toNumber() / 1e7; const burnPercentage = burnProportion.value().toNumber() / 1e7; - // Recreation on fees.ration(burn_part, treasury_part) - const split = (value: BN, part1: BN, part2: BN): [BN, BN] => { - const total = part1.add(part2); - if (total.eq(new BN(0)) || value.eq(new BN(0))) { - return [new BN(0), new BN(0)]; - } - const part1BN = value.mul(part1).div(total); - const part2BN = value.sub(part1BN); - return [part1BN, part2BN]; - }; - const calcTreasuryIncrease = (feeWithTip: bigint, tip?: bigint): bigint => { const issuanceDecrease = calcIssuanceDecrease(feeWithTip, tip); - return feeWithTip - issuanceDecrease; + const treasuryIncrease = feeWithTip - issuanceDecrease; + console.log("issuanceDecrease", issuanceDecrease.toString()); + console.log("treasuryIncrease", treasuryIncrease.toString()); + return treasuryIncrease; }; const calcIssuanceDecrease = (feeWithTip: bigint, tip?: bigint): bigint => { const feeWithTipBN = new BN(feeWithTip.toString()); const tipBN = new BN(tip?.toString() || "0"); const feeWithoutTipBN = feeWithTipBN.sub(tipBN); - const [_, burnFeePart] = split( + const [burnFeePart, _treasuryFeePart] = split( feeWithoutTipBN, burnProportion.value(), t.proportion.value() ); - const [__, burnTipPart] = split(tipBN, burnProportion.value(), t.proportion.value()); + const [burnTipPart, _treasuryTipPart] = split( + tipBN, + burnProportion.value(), + t.proportion.value() + ); + + console.log("burn percentage", burnPercentage); + console.log("treasury percentage", treasuryPercentage); + console.log("feeWithTipBN", feeWithTipBN.toString()); + console.log("tipBN", tipBN.toString()); + console.log("feeWithoutTipBN", feeWithoutTipBN.toString()); + console.log("burnFeePart", burnFeePart.toString()); + console.log("treasuryFeePart", _treasuryFeePart.toString()); + console.log("burnTipPart", burnTipPart.toString()); + console.log("treasuryTipPart", _treasuryTipPart.toString()); return BigInt(burnFeePart.add(burnTipPart).toString()); }; @@ -108,7 +125,7 @@ describeSuite({ it({ id: `T${++testCounter}`, title: - `Changing FeesTreasuryProportion to ${treasuryPercentage}% for Ethereum` + + `Changing FeesTreasuryProportion to ${treasuryPercentage}% for Ethereum ` + `${txnType} transfers`, test: async () => { const param = parameterType(