Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor(base): correct data2 serialization #555

Merged
merged 3 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions packages/base/src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,36 @@ export const WitnessArgs = WitnessArgsOf({
});

/**
* <pre>
* 0b0000000 0
* ───┬─── │
* │ ▼
* │ type - use the default vm version
* │
* ▼
* data* - use a particular vm version
* </pre>
*
* Implementation of blockchain.mol
* https://github.com/nervosnetwork/ckb/blob/5a7efe7a0b720de79ff3761dc6e8424b8d5b22ea/util/types/schemas/blockchain.mol
*/
export const HashType = createFixedBytesCodec<api.HashType>({
byteLength: 1,
pack: (type) => {
if (type === "data") return Uint8.pack(0);
if (type === "type") return Uint8.pack(1);
if (type === "data1") return Uint8.pack(2);
if (type === "data2") return Uint8.pack(3);
// prettier-ignore
if (type === "type") return Uint8.pack(0b0000000_1);
// prettier-ignore
if (type === "data") return Uint8.pack(0b0000000_0);
if (type === "data1") return Uint8.pack(0b0000001_0);
if (type === "data2") return Uint8.pack(0b0000010_0);
throw new Error(`Invalid hash type: ${type}`);
},
unpack: (buf) => {
const hashTypeBuf = Uint8.unpack(buf);
if (hashTypeBuf === 0) return "data";
if (hashTypeBuf === 1) return "type";
if (hashTypeBuf === 2) return "data1";
if (hashTypeBuf === 3) return "data2";
if (hashTypeBuf === 0b0000000_1) return "type";
if (hashTypeBuf === 0b0000000_0) return "data";
if (hashTypeBuf === 0b0000001_0) return "data1";
if (hashTypeBuf === 0b0000010_0) return "data2";
throw new Error(`Invalid hash type: ${hashTypeBuf}`);
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/base/tests/serialize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test("serialize ckb2023 script", (t) => {
const serializedHex = bytes.hexify(blockchain.Script.pack(value));
t.deepEqual(
serializedHex,
"0x3d0000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce80308000000aabbccdd44332211"
"0x3d0000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce80408000000aabbccdd44332211"
);
});

Expand Down
1 change: 1 addition & 0 deletions packages/ckb-indexer/scripts/e2e-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async function main() {

ckbProcess.kill();
indexerProcess.kill();
process.exit();
}

main();
57 changes: 30 additions & 27 deletions packages/e2e-test/scripts/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from "node:path";
import { mkdirSync, rmSync } from "node:fs";
import { retry } from "@ckb-lumos/utils";
import { RPC } from "@ckb-lumos/rpc";
import { LightClientRPC } from "@ckb-lumos/light-client";
// import { LightClientRPC } from "@ckb-lumos/light-client";
import killPort from "kill-port";
import {
ckb,
Expand All @@ -15,7 +15,7 @@ import {
CKB_RPC_PORT,
CKB_RPC_URL,
LIGHT_CLIENT_RPC_PORT,
LIGHT_CLIENT_RPC_URL,
// LIGHT_CLIENT_RPC_URL,
} from "../src/constants";

const MODULE_PATH = join(__dirname, "..");
Expand All @@ -36,7 +36,7 @@ async function main() {
mkdirSync(CKB_CWD, { recursive: true });
mkdirSync(LIGHT_CLIENT_CWD, { recursive: true });

const ckbReleaseUrl = ckb.getReleaseUrl({ version: "v0.111.0-rc1" });
const ckbReleaseUrl = ckb.getReleaseUrl({ version: "v0.111.0" });
const ckbDownloadDest = getDefaultDownloadDestination(ckbReleaseUrl);
let ckbBinaryPath = ckb.findBinaryPath(ckbDownloadDest);

Expand Down Expand Up @@ -102,34 +102,37 @@ async function main() {
cwd: LIGHT_CLIENT_CWD,
});

const lightClientProcess = spawn(
lightClientBinaryPath,
["run", "--config-file", join(LIGHT_CLIENT_CWD, "light-client.toml")],
{
stdio: "inherit",
cwd: LIGHT_CLIENT_CWD,
env: {
RUST_LOG: "info",
ckb_light_client: "info",
},
}
);

const lightClientRpc = new LightClientRPC(LIGHT_CLIENT_RPC_URL);
const lightClientTip = await retry(() => lightClientRpc.getTipHeader(), {
retries: 30,
timeout: 30_000,
delay: 100,
});

console.info("Light Client started, tip header:", lightClientTip);

execSync("npx ava '**/*.e2e.test.ts' --verbose --timeout=5m", {
// TODO uncomment me when the light client is available for CKB2023
// const lightClientProcess = spawn(
// lightClientBinaryPath,
// ["run", "--config-file", join(LIGHT_CLIENT_CWD, "light-client.toml")],
// {
// stdio: "inherit",
// cwd: LIGHT_CLIENT_CWD,
// env: {
// RUST_LOG: "info",
// ckb_light_client: "info",
// },
// }
// );

// const lightClientRpc = new LightClientRPC(LIGHT_CLIENT_RPC_URL);
// const lightClientTip = await retry(() => lightClientRpc.getTipHeader(), {
// retries: 30,
// timeout: 30_000,
// delay: 100,
// });

// console.info("Light Client started, tip header:", lightClientTip);

// TODO uncomment me when the light client is available for CKB2023
// execSync("npx ava '**/*.e2e.test.ts' --verbose --timeout=5m", {
execSync("npx ava '**/{rpc,indexer}.e2e.test.ts' --verbose --timeout=5m", {
cwd: pathTo("/"),
stdio: "inherit",
});

lightClientProcess.kill();
// lightClientProcess.kill();
ckbMinerProcess.kill();
ckbProcess.kill();

Expand Down
8 changes: 3 additions & 5 deletions packages/testkit/src/ckb-indexer-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import compareVersions from "compare-versions";
import os from "os";
// TODO dep
import downloadAndExtract from "download";
import childProcess from "node:child_process";

function log(info: string): void {
console.log(info);
Expand Down Expand Up @@ -85,10 +86,7 @@ export async function startCKBIndexer(CKBVersion?: string): Promise<void> {
await downloadCKBIndexer();
console.log("start indexer at", new Date().toLocaleString());

shell.exec(
`RUST_LOG=info ./ckb-indexer -c http://127.0.0.1:8118/rpc -l 127.0.0.1:8120 -s indexer-store-tmp`,
{
async: true,
}
childProcess.exec(
`RUST_LOG=info ./ckb-indexer -c http://127.0.0.1:8118/rpc -l 127.0.0.1:8120 -s indexer-store-tmp`
);
}