SHA256
Немного улучшен дизайн и обновлены каналы
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {readFileSync} from 'node:fs';
|
||||
import {decodeNamespace} from '../scripts/registration-v2/decode-namespace.mjs';
|
||||
const vectors=JSON.parse(readFileSync(new URL('fixtures/registration-v2.json', import.meta.url)));
|
||||
|
||||
test('старые namespace 1.0 читаются как SOL', () => {
|
||||
for (const entry of vectors.namespace) {
|
||||
const parsed=decodeNamespace(Buffer.from(entry.bytes_hex,'hex'));
|
||||
assert.equal(parsed.minor,0);
|
||||
assert.equal(parsed.currencyCode,1);
|
||||
}
|
||||
});
|
||||
test('namespace 1.1 содержит отдельный байт валюты без потери регистратора', () => {
|
||||
for (const entry of vectors.namespace) {
|
||||
const legacy=Buffer.from(entry.bytes_hex,'hex');
|
||||
const offset=5+legacy[4]+8;
|
||||
const current=Buffer.concat([legacy.subarray(0,offset),Buffer.from([1]),legacy.subarray(offset)]);
|
||||
current[1]=1;
|
||||
const old=decodeNamespace(legacy);
|
||||
const parsed=decodeNamespace(current);
|
||||
assert.equal(parsed.minor,1);
|
||||
assert.equal(parsed.currencyCode,1);
|
||||
assert.equal(parsed.registrationFeeLamports,old.registrationFeeLamports);
|
||||
assert.equal(parsed.serverLogin,old.serverLogin);
|
||||
assert.equal(parsed.name,old.name);
|
||||
const unsupported=Buffer.from(current);unsupported[offset]=2;
|
||||
assert.throws(()=>decodeNamespace(unsupported),/неподдерживаемый код валюты/);
|
||||
assert.throws(()=>decodeNamespace(current.subarray(0,-1)));
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user