SHA256
Новый протокол Solana PDA 1.2
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
parseShineUserPda,
|
||||
serializeUnsignedRecordFromState,
|
||||
} from '../../../shine-UI/js/services/shine-user-pda-service.js';
|
||||
|
||||
const bytes = (len, seed) => Uint8Array.from({ length: len }, (_, i) => (seed + i) & 0xff);
|
||||
const state = {
|
||||
login: 'codec_test',
|
||||
createdAtMs: 1_000n,
|
||||
updatedAtMs: 2_000n,
|
||||
recordNumber: 4,
|
||||
prevRecordHash: bytes(32, 1),
|
||||
rootKey: bytes(32, 40),
|
||||
clientKey: bytes(32, 80),
|
||||
forks: [
|
||||
{ blockchainKey: bytes(32, 120), createdAtMs: 1_000n, paidLimitBytes: 100_000n },
|
||||
{ blockchainKey: bytes(32, 160), createdAtMs: 2_000n, paidLimitBytes: 200_000n },
|
||||
],
|
||||
serverAddresses: [
|
||||
{ addressFormatType: 1, addressFormatVersion: 0, address: 'https://s.example' },
|
||||
],
|
||||
accessServers: ['access1'],
|
||||
};
|
||||
|
||||
const unsigned = serializeUnsignedRecordFromState(state);
|
||||
const full = new Uint8Array(unsigned.length + 64);
|
||||
full.set(unsigned);
|
||||
full.set(bytes(64, 200), unsigned.length);
|
||||
const parsed = parseShineUserPda(full);
|
||||
|
||||
assert.equal(parsed.formatMajor, 1);
|
||||
assert.equal(parsed.formatMinor, 2);
|
||||
assert.equal(parsed.isLegacy, false);
|
||||
assert.equal(parsed.recordNumber, 4);
|
||||
assert.equal(parsed.forks.length, 2);
|
||||
assert.equal(parsed.forks[1].createdAtMs, 2_000n);
|
||||
assert.equal(parsed.forks[1].paidLimitBytes, 200_000n);
|
||||
assert.equal(parsed.serverAddresses.length, 1);
|
||||
assert.deepEqual(parsed.accessServers, ['access1']);
|
||||
assert.equal(parsed.blockchain.blockchainName, 'codec_test-002');
|
||||
console.log(`PDA 1.2 codec smoke test OK (${full.length} bytes)`);
|
||||
Reference in New Issue
Block a user