Skip to content

Commit

Permalink
Feat: Add EtherPortal Specification (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunomenezes authored Aug 2, 2024
1 parent 9f00389 commit 90972f0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
26 changes: 26 additions & 0 deletions apps/web/src/components/specification/systemSpecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
erc1155SinglePortalConfig,
erc20PortalConfig,
erc721PortalConfig,
etherPortalConfig,
} from "@cartesi/rollups-wagmi";
import { Specification } from "./types";

Expand Down Expand Up @@ -126,6 +127,30 @@ const ERC721PortalSpec: Specification = {
],
} as const;

const EtherPortalSpec: Specification = {
id: "84abc4d2-a41b-426b-b294-181d82598415",
version: 1,
mode: "abi_params",
name: "Ether Portal @cartesi/[email protected]",
sliceInstructions: [
{ from: 0, to: 20, name: "sender" },
{ from: 20, to: 52, name: "amount", type: "uint256" },
],
abiParams: [],
conditionals: [
{
logicalOperator: "or",
conditions: [
{
field: "msgSender",
operator: "equals",
value: etherPortalConfig.address.toLowerCase(),
},
],
},
],
} as const;

const DAppAddressRelaySpec: Specification = {
id: "7ec6e12d-ac9c-4034-9090-9be169ac6912",
version: 1,
Expand All @@ -152,6 +177,7 @@ export const systemSpecification = {
ERC1155BatchPortalSpec,
ERC20PortalSpec,
ERC721PortalSpec,
EtherPortalSpec,
DAppAddressRelaySpec,
} as const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ describe("Specification Listing View", () => {
expect(
getByText(
elem,
"You have 5 specifications, but none of them are the type",
"You have 6 specifications, but none of them are the type",
),
).toBeInTheDocument();
expect(getByText(elem, "JSON ABI")).toBeInTheDocument();
Expand Down
15 changes: 15 additions & 0 deletions apps/web/test/components/specification/decoder.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { erc1155BatchPortalAbi, erc20Abi } from "@cartesi/rollups-wagmi";
import { describe, it } from "vitest";
import { decodePayload } from "../../../src/components/specification/decoder";
import { systemSpecification } from "../../../src/components/specification/systemSpecs";
import { Specification } from "../../../src/components/specification/types";
import { encodedDataSamples } from "./encodedData.stubs";

Expand Down Expand Up @@ -218,6 +219,20 @@ Slice name: "from" (Is it the right one?)`,
);
});

describe("Portal cases", () => {
it("should decode ether-portal data without the exec-layer information", () => {
const envelope = decodePayload(
systemSpecification.EtherPortalSpec,
encodedDataSamples.etherPortalSampleWithoutExecLayer,
);

expect(envelope.result).toEqual({
amount: 10000000000000000n,
sender: "0x0c70e9a737aa92055c8c1217bf887a65cb2292f4",
});
});
});

describe("Struct definition example cases", () => {
it("should support setting a separate struct definition to decode abi-encoded data", () => {
const spec: Specification = {
Expand Down
8 changes: 8 additions & 0 deletions apps/web/test/components/specification/encodedData.stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ const wagmiSample: Hex =
const encodedDataSampleWithStruct: Hex =
"0x000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000028367fe226cd9e5699f4288d512fe3a4a4a001200000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000002";

const etherPortalSampleWithExecLayer: Hex =
"0x3a146915527bd1528026b5c14335098dff2700ca000000000000000000000000000000000000000000000000000000000000012c33303020657468206465706f736974656420746f20307833613134363931353532376264313532383032366235633134333335303938646666323730306361";

const etherPortalSampleWithoutExecLayer: Hex =
"0x0c70e9a737aa92055c8c1217bf887a65cb2292f4000000000000000000000000000000000000000000000000002386f26fc10000";

export const encodedDataSamples = {
wagmiSample,
encodedDataSampleWithStruct,
etherPortalSampleWithExecLayer,
etherPortalSampleWithoutExecLayer,
};

0 comments on commit 90972f0

Please sign in to comment.