Skip to content
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
5 changes: 0 additions & 5 deletions packages/borsh/tsconfig.test.json

This file was deleted.

5 changes: 5 additions & 0 deletions packages/borsh/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../config/tsconfig.test.json",
"include": ["src/**/*", "tests/**/*"]
}
16 changes: 15 additions & 1 deletion packages/sdk-core/src/encryptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export async function generateRsaKeypair(): Promise<CryptoKeyPair> {
return await subtle().generateKey(
{
name: 'RSA-OAEP',
modulusLength: 512,
modulusLength: 2048,
publicExponent: publicExponent,
hash: 'SHA-256',
},
Expand Down Expand Up @@ -387,6 +387,20 @@ export class Encryptor implements IEncryptor {
this.#publicKeys = new Map()
}

static async create(_: string, __?: IStorage): Promise<Encryptor> {
const encryptor = new Encryptor()
encryptor.#privateKey = await NodePrivateKey.initialize()
return encryptor
}

async exportPublicKey(): Promise<IPublicKeyRaws> {
if (!this.#privateKey) throw new Error('No credential available for public key export')
return {
rsa: await exportRsaPublicKey(this.#privateKey.rsa.publicKey),
ec: await exportEcPublicKey(this.#privateKey.ec.publicKey),
}
}

async importCredentials(originalSecret: Uint8Array, addr: string, credentials: Credentials): Promise<void> {

console.debug(`Import credentials for node: ${addr}`)
Expand Down
1 change: 0 additions & 1 deletion packages/sdk-core/tests/events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ describe('Serialization', () => {
players: [
new GamePlayer({
id: 1n,
position: 1,
}),
],
})
Expand Down
5 changes: 0 additions & 5 deletions packages/sdk-core/tsconfig.test.json

This file was deleted.

5 changes: 5 additions & 0 deletions packages/sdk-core/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../config/tsconfig.test.json",
"include": ["src/**/*", "tests/**/*"]
}
1 change: 0 additions & 1 deletion packages/sdk-facade/jest.config.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/sdk-facade/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../config/jest.config.js')
5 changes: 0 additions & 5 deletions packages/sdk-facade/tsconfig.test.json

This file was deleted.

5 changes: 5 additions & 0 deletions packages/sdk-facade/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../config/tsconfig.test.json",
"include": ["src/**/*", "tests/**/*"]
}
1 change: 0 additions & 1 deletion packages/sdk-solana/jest.config.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/sdk-solana/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../config/jest.config.js')
89 changes: 50 additions & 39 deletions packages/sdk-solana/tests/accounts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,46 @@ import { assert } from 'chai';
import {
GameReg,
GameState,
PlayerJoin,
PlayerBalance,
PlayerDeposit,
PlayerState,
RegistryState,
ServerJoin,
ServerState,
Vote,
} from '../src/accounts';
import { PublicKey } from '@solana/web3.js';
import { REG_ACCOUNT_DATA } from './account_data';
import { EntryTypeCash } from '@race-foundation/sdk-core';
import { address } from '@solana/kit';

const ADDR_1 = address('11111111111111111111111111111111');
const ADDR_2 = address('So11111111111111111111111111111111111111112');
const ADDR_3 = address('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s');
const ADDR_4 = address('C3u1cTJGKP5XzPCvLgQydGWE7aR3x3o5KL8YooFfY4RN');
const ADDR_5 = address('SysvarRent111111111111111111111111111111111');

describe('Test account data serialization', () => {
it('PlayerState', () => {
let state = new PlayerState({
isInitialized: true,
version: 2,
nick: '16-char_nickname',
pfpKey: PublicKey.default,
pfpKey: ADDR_1,
credentials: Uint8Array.of(1, 2, 3),
});
let buf = Buffer.from([
1, 16, 0, 0, 0, 49, 54, 45, 99, 104, 97, 114, 95, 110, 105, 99, 107, 110, 97, 109, 101, 1, 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, 72, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]);
let buf = state.serialize();
let deserialized = PlayerState.deserialize(buf);
assert.equal(state.version, deserialized.version);
assert.equal(state.nick, deserialized.nick);
assert.deepStrictEqual(state.pfpKey, deserialized.pfpKey);
assert.equal(state.isInitialized, deserialized.isInitialized);
assert.deepStrictEqual(state.credentials, deserialized.credentials);
});

it('PlayerState with no pfp', () => {
let state = new PlayerState({
isInitialized: true,
version: 2,
nick: 'Alice',
pfpKey: undefined,
credentials: Uint8Array.of(),
});
let buf = state.serialize();
let deserialized = PlayerState.deserialize(buf);
Expand All @@ -55,18 +60,18 @@ describe('Test account data serialization', () => {
isInitialized: true,
isPrivate: false,
size: 100,
ownerKey: PublicKey.unique(),
ownerKey: ADDR_1,
games: [
new GameReg({
gameKey: PublicKey.unique(),
gameKey: ADDR_2,
title: 'Game A',
bundleKey: PublicKey.unique(),
bundleKey: ADDR_3,
regTime: BigInt(1000),
}),
new GameReg({
gameKey: PublicKey.unique(),
gameKey: ADDR_4,
title: 'Game B',
bundleKey: PublicKey.unique(),
bundleKey: ADDR_5,
regTime: BigInt(2000),
}),
],
Expand All @@ -76,35 +81,32 @@ describe('Test account data serialization', () => {
assert.deepStrictEqual(state, deserialized);
});

// TODO: Fix this
// it('GameState deserialize', () => {
// let deserialized = GameState.deserialize(Buffer.from(ACCOUNT_DATA));
// });

it('GameState', () => {
let state = new GameState({
isInitialized: true,
version: "0.2.2",
version: '0.2.2',
title: 'test game name',
bundleKey: PublicKey.unique(),
stakeKey: PublicKey.unique(),
ownerKey: PublicKey.unique(),
tokenKey: PublicKey.unique(),
transactorKey: PublicKey.unique(),
bundleKey: ADDR_1,
stakeKey: ADDR_2,
ownerKey: ADDR_3,
tokenKey: ADDR_4,
transactorKey: ADDR_5,
accessVersion: BigInt(1),
settleVersion: BigInt(2),
maxPlayers: 10,
players: [
new PlayerJoin({
key: PublicKey.unique(),
balance: BigInt(100),
playersRegAccount: ADDR_1,
deposits: [
new PlayerDeposit({
key: ADDR_2,
amount: BigInt(100),
accessVersion: BigInt(1),
position: 0,
settleVersion: BigInt(2),
status: 0,
}),
],
servers: [
new ServerJoin({
key: PublicKey.unique(),
key: ADDR_3,
endpoint: 'http://foo.bar',
accessVersion: BigInt(2),
}),
Expand All @@ -113,8 +115,8 @@ describe('Test account data serialization', () => {
data: Uint8Array.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
votes: [
new Vote({
voterKey: PublicKey.unique(),
voteeKey: PublicKey.unique(),
voterKey: ADDR_4,
voteeKey: ADDR_5,
voteType: 0,
}),
],
Expand All @@ -123,8 +125,16 @@ describe('Test account data serialization', () => {
minDeposit: BigInt(100),
maxDeposit: BigInt(100),
}),
recipientAddr: PublicKey.unique(),
recipientAddr: ADDR_2,
checkpoint: Uint8Array.of(1, 2, 3, 4),
entryLock: 0,
bonuses: [],
balances: [
new PlayerBalance({
playerId: BigInt(1),
balance: BigInt(100),
}),
],
});
let buf = state.serialize();
let deserialized = GameState.deserialize(buf);
Expand All @@ -134,9 +144,10 @@ describe('Test account data serialization', () => {
it('ServerState', () => {
let state = new ServerState({
isInitialized: true,
key: PublicKey.unique(),
ownerKey: PublicKey.unique(),
key: ADDR_1,
ownerKey: ADDR_2,
endpoint: 'http://foo.bar',
credentials: Uint8Array.of(1, 2, 3),
});
let buf = state.serialize();
let deserialized = ServerState.deserialize(buf);
Expand Down
19 changes: 12 additions & 7 deletions packages/sdk-solana/tests/instruction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { EntryTypeCash } from '@race-foundation/sdk-core';

describe('Test instruction serialization', () => {
it('CreatePlayerProfile', () => {
const data = new CreatePlayerProfileData('Alice');
const data = new CreatePlayerProfileData('Alice', Uint8Array.of(1, 2, 3));
const serialized = data.serialize();
const expected = Buffer.from([3, 5, 0, 0, 0, 65, 108, 105, 99, 101]);
const expected = Buffer.from([3, 5, 0, 0, 0, 65, 108, 105, 99, 101, 3, 0, 0, 0, 1, 2, 3]);
assert.deepStrictEqual(serialized, expected);
});

Expand Down Expand Up @@ -54,11 +54,16 @@ describe('Test instruction serialization', () => {
});

it('JoinGame', () => {
const data = new JoinGameData(1000n, 0n, 2, 'key0');
const serialized = data.serialize();
const expected = Buffer.from([
10, 232, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 4, 0, 0, 0, 107, 101, 121, 48,
]);
const data = new JoinGameData({
amount: 1000n,
accessVersion: 0n,
settleVersion: 2n,
position: 4,
});
const serialized = Array.from(data.serialize());
const expected = [
10, 232, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 4, 0,
];
assert.deepStrictEqual(serialized, expected);
});
});
5 changes: 0 additions & 5 deletions packages/sdk-solana/tsconfig.test.json

This file was deleted.

5 changes: 5 additions & 0 deletions packages/sdk-solana/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../config/tsconfig.test.json",
"include": ["src/**/*", "tests/**/*"]
}
1 change: 0 additions & 1 deletion packages/sdk-sui/jest.config.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/sdk-sui/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../config/jest.config.js')
1 change: 0 additions & 1 deletion packages/sdk-sui/tsconfig.test.json

This file was deleted.

5 changes: 5 additions & 0 deletions packages/sdk-sui/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../config/tsconfig.test.json",
"include": ["src/**/*", "tests/**/*"]
}
Loading