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)`);
|
||||
@@ -1,3 +1,4 @@
|
||||
// Legacy 1.0 e2e kept only as a historical fixture. PDA 1.2 uses the native compact instruction wire format; see pda-v1-2-codec.mjs and the 1.2 format spec.
|
||||
import * as anchor from "@coral-xyz/anchor";
|
||||
import { Program } from "@coral-xyz/anchor";
|
||||
import {
|
||||
@@ -189,7 +190,7 @@ function extractSigFromEdIx(ixData: Buffer): Buffer {
|
||||
return ixData.subarray(signatureOffset, signatureOffset + 64);
|
||||
}
|
||||
|
||||
describe("shine_users e2e", () => {
|
||||
describe.skip("legacy shine_users PDA 1.0 e2e (reference only)", () => {
|
||||
anchor.setProvider(anchor.AnchorProvider.env());
|
||||
const provider = anchor.getProvider() as anchor.AnchorProvider;
|
||||
const program = anchor.workspace.shine as Program<Shine>;
|
||||
|
||||
Reference in New Issue
Block a user