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

[ts-sdk] Add e2e localnet tests #4605

Merged
merged 4 commits into from
Sep 13, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/explorer-client-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
uses: cypress-io/github-action@v4
with:
install: false
start: pnpm dlx concurrently 'cargo run --bin sui-test-validator' 'pnpm dev:local'
start: pnpm dlx concurrently --kill-others 'cargo run --bin sui-test-validator' 'pnpm dev:local'
working-directory: ./explorer/client
spec: cypress/e2e/localnet/*
# Wait on faucet and explorer:
Expand Down
23 changes: 22 additions & 1 deletion .github/workflows/ts-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Test
run: pnpm --filter @mysten/sui.js test
run: pnpm --filter @mysten/sui.js test:unit
- name: Build
run: pnpm --filter @mysten/sui.js build
end_to_end:
name: End-to-end tests
needs: diff
if: needs.diff.outputs.isTypescriptSDK == 'true'
runs-on: [ubuntu-ghcloud]
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- uses: pnpm/action-setup@v2.2.2
with:
version: 7
- run: cargo build --bin sui-test-validator --profile dev
- name: Install Nodejs
uses: actions/setup-node@v3
with:
node-version: "16"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run e2e tests
run: pnpm dlx concurrently --kill-others --success command-1 'cargo run --bin sui-test-validator' 'pnpm --filter @mysten/sui.js test:e2e'
34 changes: 34 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions sdk/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"build": "node ./type_guards.mjs && pnpm build:types && tsup ./src/index.ts --format esm,cjs --sourcemap",
"build:types": "tsc --build",
"doc": "typedoc",
"test": "vitest",
"test": "pnpm test:unit && pnpm test:e2e",
"test:unit": "vitest unit",
"test:e2e": "wait-on http://127.0.0.1:9123 -l --timeout 120000 && vitest e2e",
"lint": "eslint './{src,test}/**.{ts,js}'",
"prepublishOnly": "pnpm build",
"size": "size-limit",
Expand Down Expand Up @@ -76,7 +78,8 @@
"tsup": "^6.2.2",
"typedoc": "^0.23.11",
"typescript": "^4.8.2",
"vitest": "^0.22.1"
"vitest": "^0.22.1",
"wait-on": "^6.0.1"
},
"dependencies": {
"@mysten/bcs": "workspace:*",
Expand All @@ -86,9 +89,9 @@
"buffer": "^6.0.3",
"cross-fetch": "^3.1.5",
"jayson": "^3.6.6",
"rpc-websockets": "^7.5.0",
"js-sha3": "^0.8.0",
"lossless-json": "^1.0.5",
"rpc-websockets": "^7.5.0",
"tweetnacl": "^1.0.3"
}
}
6 changes: 6 additions & 0 deletions sdk/typescript/test/e2e/example.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { describe } from 'vitest';

describe.todo('Write some tests that run against localnet.');
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import nacl from 'tweetnacl';
import { describe, it, expect } from 'vitest';
import { Base64DataBuffer, Ed25519Keypair } from '../../src';
import { Base64DataBuffer, Ed25519Keypair } from '../../../src';

const VALID_SECRET_KEY =
'mdqVWeFekT7pqy5T49+tV12jO0m+ESW7ki4zSU9JiCgbL0kJbj5dvQ/PqcDAzZLZqzshVEs01d1KZdmLh4uZIg==';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,49 @@
// SPDX-License-Identifier: Apache-2.0

import { describe, it, expect } from 'vitest';
import { Ed25519PublicKey } from '../../src';
import { Ed25519PublicKey } from '../../../src';

// Test case generated against CLI:
// cargo build --bin sui
// ../sui/target/debug/sui client new-address ed25519
// ../sui/target/debug/sui keytool list
let TEST_CASES = new Map<string, string>([
["UdGRWooy48vGTs0HBokIis5NK+DUjiWc9ENUlcfCCBE=", "3415400a4bfdf924aefa55446e5f4cd6e9a9399f"],
["0PTAfQmNiabgbak9U/stWZzKc5nsRqokda2qnV2DTfg=", "2e6dad710b343b8655825bc420783aaa5ade08c2"],
["6L/l0uhGt//9cf6nLQ0+24Uv2qanX/R6tn7lWUJX1Xk=", "607a2403069d547c3fbba4b9e22793c7d78abb1f"],
["6qZ88i8NJjaD+qZety3qXi4pLptGKS3wwO8bfDmUD+Y=", "7a4b0fd76cce17ef014d64ec5e073117bfc0b4de"],
["RgdFhZXGe21x48rhe9X+Kh/WyFCo9ft6e9nQKZYHpi0=", "ecd7ef15f92a26bc8f22a88a7786fe1aae1051c6"],
[
'UdGRWooy48vGTs0HBokIis5NK+DUjiWc9ENUlcfCCBE=',
'3415400a4bfdf924aefa55446e5f4cd6e9a9399f',
],
[
'0PTAfQmNiabgbak9U/stWZzKc5nsRqokda2qnV2DTfg=',
'2e6dad710b343b8655825bc420783aaa5ade08c2',
],
[
'6L/l0uhGt//9cf6nLQ0+24Uv2qanX/R6tn7lWUJX1Xk=',
'607a2403069d547c3fbba4b9e22793c7d78abb1f',
],
[
'6qZ88i8NJjaD+qZety3qXi4pLptGKS3wwO8bfDmUD+Y=',
'7a4b0fd76cce17ef014d64ec5e073117bfc0b4de',
],
[
'RgdFhZXGe21x48rhe9X+Kh/WyFCo9ft6e9nQKZYHpi0=',
'ecd7ef15f92a26bc8f22a88a7786fe1aae1051c6',
],
]);

const VALID_KEY_BASE64 = 'Uz39UFseB/B38iBwjesIU1JZxY6y+TRL9P84JFw41W4=';

const BASE64_KEY_BYTES = [
180,
107,
26,
32,
169,
88,
248,
46,
88,
100,
108,
243,
255,
87,
146,
92,
42,
147,
104,
2,
39,
200,
114,
145,
37,
122,
8,
37,
170,
238,
164,
236,
180, 107, 26, 32, 169, 88, 248, 46, 88, 100, 108, 243, 255, 87, 146, 92, 42,
147, 104, 2, 39, 200, 114, 145, 37, 122, 8, 37, 170, 238, 164, 236,
];

describe('Ed25519PublicKey', () => {
it('invalid', () => {
// public key length 33 is invalid for Ed25519
expect(() => {
new Ed25519PublicKey([
3,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
]);
}).toThrow();

Expand Down Expand Up @@ -142,4 +96,4 @@ describe('Ed25519PublicKey', () => {
expect(key.toSuiAddress()).toEqual(address);
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { Base64DataBuffer, Secp256k1Keypair } from '../../src';
import { Base64DataBuffer, Secp256k1Keypair } from '../../../src';
import { describe, it, expect } from 'vitest';
import * as secp from "@noble/secp256k1";
import * as secp from '@noble/secp256k1';

// Test case from https://github.com/rust-bitcoin/rust-secp256k1/blob/master/examples/sign_verify.rs#L26
const VALID_SECP256K1_SECRET_KEY = [
59, 148, 11, 85, 134, 130, 61, 253, 2, 174, 59, 70, 27, 180, 51, 107,
94, 203, 174, 253, 102, 39, 170, 146, 46, 252, 4, 143, 236, 12, 136, 28,
59, 148, 11, 85, 134, 130, 61, 253, 2, 174, 59, 70, 27, 180, 51, 107, 94, 203,
174, 253, 102, 39, 170, 146, 46, 252, 4, 143, 236, 12, 136, 28,
];

// Corresponding to the secret key above.
// Corresponding to the secret key above.
export const VALID_SECP256K1_PUBLIC_KEY = [
2, 29, 21, 35, 7, 198, 183, 43, 14, 208, 65, 139, 14, 112, 205, 128, 231,
245, 41, 91, 141, 134, 245, 114, 45, 63, 82, 19, 251, 210, 57, 79, 54,
2, 29, 21, 35, 7, 198, 183, 43, 14, 208, 65, 139, 14, 112, 205, 128, 231, 245,
41, 91, 141, 134, 245, 114, 45, 63, 82, 19, 251, 210, 57, 79, 54,
];

// Invalid private key with incorrect length
Expand Down Expand Up @@ -49,7 +49,9 @@ describe('secp256k1-keypair', () => {
});

it('generate keypair from random seed', () => {
const keypair = Secp256k1Keypair.fromSeed(Uint8Array.from(Array(32).fill(8)));
const keypair = Secp256k1Keypair.fromSeed(
Uint8Array.from(Array(32).fill(8))
);
expect(keypair.getPublicKey().toBase64()).toEqual(
'A/mR+UTR4ZVKf8i5v2Lg148BX0wHdi1QXiDmxFJgo2Yb'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,35 @@
// SPDX-License-Identifier: Apache-2.0

import { describe, it, expect } from 'vitest';
import { Secp256k1PublicKey } from '../../src/cryptography/secp256k1-publickey';
import { INVALID_SECP256K1_PUBLIC_KEY, VALID_SECP256K1_PUBLIC_KEY } from './secp256k1-keypair.test';
import { Secp256k1PublicKey } from '../../../src/cryptography/secp256k1-publickey';
import {
INVALID_SECP256K1_PUBLIC_KEY,
VALID_SECP256K1_PUBLIC_KEY,
} from './secp256k1-keypair.test';

// Test case generated against CLI:
// cargo build --bin sui
// ../sui/target/debug/sui client new-address secp256k1
// ../sui/target/debug/sui keytool list
let SECP_TEST_CASES = new Map<string, string>([
["AwTC3jVFRxXc3RJIFgoQcv486QdqwYa8vBp4bgSq0gsI", "35057079b5dfc60d650768e2f4f92318f4ea5a77"],
["A1F2CtldIGolO92Pm9yuxWXs5E07aX+6ZEHAnSuKOhii", "0187cf4234ff80862d5a1665d840df400fef29a0"],
["Ak5rsa5Od4T6YFN/V3VIhZ/azMMYPkUilKQwc+RiaId+", "70eaff6b7973c57842c2272f00aa19af9f20dc1b"],
["A4XbJ3fLvV/8ONsnLHAW1nORKsoCYsHaXv9FK1beMtvY", "deb28f733d9f59910cb210d56a46614f9dd28360"],
[
'AwTC3jVFRxXc3RJIFgoQcv486QdqwYa8vBp4bgSq0gsI',
'35057079b5dfc60d650768e2f4f92318f4ea5a77',
],
[
'A1F2CtldIGolO92Pm9yuxWXs5E07aX+6ZEHAnSuKOhii',
'0187cf4234ff80862d5a1665d840df400fef29a0',
],
[
'Ak5rsa5Od4T6YFN/V3VIhZ/azMMYPkUilKQwc+RiaId+',
'70eaff6b7973c57842c2272f00aa19af9f20dc1b',
],
[
'A4XbJ3fLvV/8ONsnLHAW1nORKsoCYsHaXv9FK1beMtvY',
'deb28f733d9f59910cb210d56a46614f9dd28360',
],
]);
describe('Secp256k1PublicKey', () => {
describe('Secp256k1PublicKey', () => {
it('invalid', () => {
expect(() => {
new Secp256k1PublicKey(INVALID_SECP256K1_PUBLIC_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// SPDX-License-Identifier: Apache-2.0

import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
import { JsonRpcClient } from '../../src/rpc/client';
import { JsonRpcClient } from '../../../src/rpc/client';
import {
mockRpcResponse,
mockServer,
MOCK_ENDPOINT,
MOCK_PORT,
} from '../mocks/rpc-http';
import { isGetOwnedObjectsResponse } from '../../src/types/index.guard';
import { SuiObjectInfo } from '../../src';
import { isGetOwnedObjectsResponse } from '../../../src/types/index.guard';
import { SuiObjectInfo } from '../../../src';

const EXAMPLE_OBJECT: SuiObjectInfo = {
objectId: '8dc6a6f70564e29a01c7293a9c03818fda2d049f',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

import nacl from 'tweetnacl';
import { describe, it, expect } from 'vitest';
import { Base64DataBuffer, Ed25519Keypair, RawSigner, Secp256k1Keypair } from '../../src';
import * as secp from "@noble/secp256k1";
import {
Base64DataBuffer,
Ed25519Keypair,
RawSigner,
Secp256k1Keypair,
} from '../../../src';
import * as secp from '@noble/secp256k1';

describe('RawSigner', () => {
it('Ed25519 keypair signData', async () => {
Expand Down
Loading