SHA256
33 lines
1.5 KiB
JavaScript
33 lines
1.5 KiB
JavaScript
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 vec=JSON.parse(readFileSync(new URL('./fixtures/registration-v2.json',import.meta.url)));
|
|
function throws(data,msg){assert.throws(()=>decodeNamespace(data),msg);}
|
|
test('Декодирование paid/free namespaces',()=>{
|
|
const shine=decodeNamespace(Buffer.from(vec.namespace[0].bytes_hex,'hex'));
|
|
const free=decodeNamespace(Buffer.from(vec.namespace[1].bytes_hex,'hex'));
|
|
assert.equal(shine.registrarPubkeyHex,null);
|
|
assert.equal(shine.serverLogin,null);
|
|
assert.equal(shine.registrationFeeLamports,'10000000');
|
|
assert.equal(free.serverLogin,'registrar@shine');
|
|
assert.equal(free.minLocalLen,3);
|
|
});
|
|
test('Некорректный namespace не пройдет строгий декодер',()=>{
|
|
const canonical=Buffer.from(vec.namespace[1].bytes_hex,'hex');
|
|
for(const index of [0,1,2,3,4]){
|
|
const bad=Buffer.from(canonical);bad[index]=index===1?1:0;
|
|
throws(bad);
|
|
}
|
|
throws(canonical.subarray(0,-1));
|
|
throws(Buffer.concat([canonical,Buffer.from([0])]));
|
|
const bad=Buffer.from(canonical);
|
|
bad[5]='F'.charCodeAt(0);
|
|
throws(bad);
|
|
});
|
|
test('Некорректный server login отвергается',()=>{
|
|
const canonical=Buffer.from(vec.namespace[1].bytes_hex,'hex');
|
|
const bad=Buffer.from(canonical);bad[bad.length-1]='@'.charCodeAt(0);
|
|
throws(bad);
|
|
});
|