Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
fgamundi committed Nov 20, 2023
1 parent 912b14a commit b588784
Show file tree
Hide file tree
Showing 4 changed files with 471 additions and 481 deletions.
88 changes: 38 additions & 50 deletions test/helpers/eth-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,50 @@ import "@moonbeam-network/api-augment";
import { expect } from "@moonwall/cli";
import { EventRecord } from "@polkadot/types/interfaces";
import {
EvmCoreErrorExitError,
EvmCoreErrorExitFatal,
EvmCoreErrorExitReason,
EvmCoreErrorExitRevert,
EvmCoreErrorExitSucceed,
EvmCoreErrorExitError,
EvmCoreErrorExitFatal,
EvmCoreErrorExitReason,
EvmCoreErrorExitRevert,
EvmCoreErrorExitSucceed,
} from "@polkadot/types/lookup";
export type Errors = {
Succeed: EvmCoreErrorExitSucceed["type"];
Error: EvmCoreErrorExitError["type"];
Revert: EvmCoreErrorExitRevert["type"];
Fatal: EvmCoreErrorExitFatal["type"];
Succeed: EvmCoreErrorExitSucceed["type"];
Error: EvmCoreErrorExitError["type"];
Revert: EvmCoreErrorExitRevert["type"];
Fatal: EvmCoreErrorExitFatal["type"];
};


export function expectEVMResult<T extends Errors, Type extends keyof T>(
events: EventRecord[],
resultType: Type,
reason?: T[Type]
events: EventRecord[],
resultType: Type,
reason?: T[Type]
) {
expect(events, `Missing events, probably failed execution`).to.be.length.at.least(1);
const ethereumResult = events.find(
({ event: { section, method } }) => section == "ethereum" && method == "Executed"
)!.event.data[3] as EvmCoreErrorExitReason;
expect(events, `Missing events, probably failed execution`).to.be.length.at.least(1);
const ethereumResult = events.find(
({ event: { section, method } }) => section == "ethereum" && method == "Executed"
)!.event.data[3] as EvmCoreErrorExitReason;

const foundReason = ethereumResult.isError
? ethereumResult.asError.type
: ethereumResult.isFatal
? ethereumResult.asFatal.type
: ethereumResult.isRevert
? ethereumResult.asRevert.type
: ethereumResult.asSucceed.type;
const foundReason = ethereumResult.isError
? ethereumResult.asError.type
: ethereumResult.isFatal
? ethereumResult.asFatal.type
: ethereumResult.isRevert
? ethereumResult.asRevert.type
: ethereumResult.asSucceed.type;

expect(
ethereumResult.type,
`Invalid EVM Execution - (${ethereumResult.type}.${foundReason})`
).to.equal(resultType);
if (reason) {
if (ethereumResult.isError) {
expect(
ethereumResult.asError.type,
`Invalid EVM Execution ${ethereumResult.type} Reason`
).to.equal(reason);
} else if (ethereumResult.isFatal) {
expect(
ethereumResult.asFatal.type,
`Invalid EVM Execution ${ethereumResult.type} Reason`
).to.equal(reason);
} else if (ethereumResult.isRevert) {
expect(
ethereumResult.asRevert.type,
`Invalid EVM Execution ${ethereumResult.type} Reason`
).to.equal(reason);
} else
expect(
ethereumResult.asSucceed.type,
`Invalid EVM Execution ${ethereumResult.type} Reason`
).to.equal(reason);
}
expect(ethereumResult.type, `Invalid EVM Execution - (${ethereumResult.type}.${foundReason})`).to.equal(resultType);
if (reason) {
if (ethereumResult.isError) {
expect(ethereumResult.asError.type, `Invalid EVM Execution ${ethereumResult.type} Reason`).to.equal(reason);
} else if (ethereumResult.isFatal) {
expect(ethereumResult.asFatal.type, `Invalid EVM Execution ${ethereumResult.type} Reason`).to.equal(reason);
} else if (ethereumResult.isRevert) {
expect(ethereumResult.asRevert.type, `Invalid EVM Execution ${ethereumResult.type} Reason`).to.equal(
reason
);
} else
expect(ethereumResult.asSucceed.type, `Invalid EVM Execution ${ethereumResult.type} Reason`).to.equal(
reason
);
}
}
2 changes: 1 addition & 1 deletion test/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./eth-transactions";
export * from "./xcm";
export * from "./xcm";
34 changes: 17 additions & 17 deletions test/helpers/xcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import { DevModeContext } from "@moonwall/cli";
import { u8aToHex } from "@polkadot/util";

export function descendOriginFromAddress20(
context: DevModeContext,
address: `0x${string}` = "0x0101010101010101010101010101010101010101",
paraId: number = 1
context: DevModeContext,
address: `0x${string}` = "0x0101010101010101010101010101010101010101",
paraId: number = 1
) {
const toHash = new Uint8Array([
...new TextEncoder().encode("SiblingChain"),
...context.polkadotJs().createType("Compact<u32>", paraId).toU8a(),
...context
.polkadotJs()
.createType("Compact<u32>", "AccountKey20".length + 20)
.toU8a(),
...new TextEncoder().encode("AccountKey20"),
...context.polkadotJs().createType("AccountId", address).toU8a(),
]);
const toHash = new Uint8Array([
...new TextEncoder().encode("SiblingChain"),
...context.polkadotJs().createType("Compact<u32>", paraId).toU8a(),
...context
.polkadotJs()
.createType("Compact<u32>", "AccountKey20".length + 20)
.toU8a(),
...new TextEncoder().encode("AccountKey20"),
...context.polkadotJs().createType("AccountId", address).toU8a(),
]);

return {
originAddress: address,
descendOriginAddress: u8aToHex(context.polkadotJs().registry.hash(toHash).slice(0, 20)),
};
return {
originAddress: address,
descendOriginAddress: u8aToHex(context.polkadotJs().registry.hash(toHash).slice(0, 20)),
};
}
Loading

0 comments on commit b588784

Please sign in to comment.