Перевести донаты на Stars и обновить Devnet

This commit is contained in:
AidarKC
2026-11-14 00:55:02 +03:00
parent c972a975fd
commit 97db033eb8
39 changed files with 1020 additions and 198 deletions
+85
View File
@@ -0,0 +1,85 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import vm from 'node:vm';
import {
deriveStarsPythOracleAccounts,
getStarsQuoteFromRpc,
parseVerifiedPythPriceAccount,
PYTH_SOL_USD_FEED_ID,
PYTH_USDT_USD_FEED_ID,
PYTH_RECEIVER_PROGRAM_ID,
} from '../js/services/shine-stars-pyth.js';
const validOwner = { toBase58: () => PYTH_RECEIVER_PROGRAM_ID };
const now = 1_800_000_000;
const discr = [34,241,35,99,157,126,244,205];
function fakePrice(feed, value, { publish = now - 15, confidence = 20_000_000n, verified = true, owner = validOwner, exponent = -8 } = {}) {
const bytes = new Uint8Array(133);
bytes.set(discr);
bytes[40] = verified ? 1 : 0;
bytes.set(Uint8Array.from(feed.match(/../g), (hex) => parseInt(hex, 16)), 41);
const v = new DataView(bytes.buffer);
v.setBigInt64(73, BigInt(value), true);
v.setBigUint64(81, confidence, true);
v.setInt32(89, exponent, true);
v.setBigInt64(93, BigInt(publish), true);
return { owner, data: bytes };
}
const solPrice = fakePrice(PYTH_SOL_USD_FEED_ID, 15_000_000_000n); // $150.00
const usdtPrice = fakePrice(PYTH_USDT_USD_FEED_ID, 100_000_000n, {confidence: 1000n}); // $1.00
// Browser-vendored Solana web3.js; no network required, same code as production.
const context = { Buffer, Uint8Array, TextEncoder, TextDecoder, console, setTimeout, crypto: globalThis.crypto };
vm.createContext(context);
vm.runInContext(readFileSync(new URL('../js/vendor/solana-web3.iife.min.js', import.meta.url), 'utf8'), context);
const solana = context.solanaWeb3;
test('derive shard-0 Pyth Core oracle PDAs (official mainnet examples)', () => {
assert.deepEqual(deriveStarsPythOracleAccounts(solana), {
solUsd: '7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE',
usdtUsd: 'HT2PLQBcG5EiCcNSaMHAjSgd9F98ecpATbk4Sk5oYuM',
});
});
test('read raw Anchor PriceUpdateV2 without precision loss', () => {
assert.equal(parseVerifiedPythPriceAccount(solPrice, PYTH_SOL_USD_FEED_ID, now).priceE8, 15_000_000_000n);
assert.equal(parseVerifiedPythPriceAccount(usdtPrice, PYTH_USDT_USD_FEED_ID, now).priceE8, 100_000_000n);
});
test('fail closed for stale/future/unverified/malformed/foreign price accounts', () => {
assert.throws(() => parseVerifiedPythPriceAccount(fakePrice(PYTH_SOL_USD_FEED_ID, 15_000_000_000n, {publish: now - 3_601}), PYTH_SOL_USD_FEED_ID, now), /устарела/);
assert.throws(() => parseVerifiedPythPriceAccount(fakePrice(PYTH_SOL_USD_FEED_ID, 15_000_000_000n, {publish: now + 16}), PYTH_SOL_USD_FEED_ID, now), /время/);
assert.throws(() => parseVerifiedPythPriceAccount(fakePrice(PYTH_SOL_USD_FEED_ID, 15_000_000_000n, {verified:false}), PYTH_SOL_USD_FEED_ID, now), /проверку/);
assert.throws(() => parseVerifiedPythPriceAccount(fakePrice(PYTH_SOL_USD_FEED_ID, 15_000_000_000n), PYTH_USDT_USD_FEED_ID, now), /другую/);
assert.throws(() => parseVerifiedPythPriceAccount(fakePrice(PYTH_SOL_USD_FEED_ID, 15_000_000_000n, {owner:{toBase58:()=> 'Bad'}}), PYTH_SOL_USD_FEED_ID, now), /владельца/);
assert.throws(() => parseVerifiedPythPriceAccount(fakePrice(PYTH_SOL_USD_FEED_ID, 15_000_000_000n, {confidence: 150_000_001n}), PYTH_SOL_USD_FEED_ID, now), /интервал/);
const invalid = fakePrice(PYTH_SOL_USD_FEED_ID, 15_000_000_000n);
invalid.data[0] ^= 1;
assert.throws(() => parseVerifiedPythPriceAccount(invalid, PYTH_SOL_USD_FEED_ID, now), /формат/);
});
test('request both accounts once from authenticated Solana RPC, no Hermes', async () => {
let invoked = 0;
const connection = { getMultipleAccountsInfo: async (keys, commitment) => {
invoked++;
assert.equal(keys.length, 2);
assert.equal(commitment, 'confirmed');
assert.equal(keys[0].toBase58(), '7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE');
return [solPrice, usdtPrice];
} };
const quote = await getStarsQuoteFromRpc({ solanaEndpoint: 'https://test.shineup.me/solana-rpc', solana, connection, nowSeconds: now });
assert.equal(quote.solUsdE8, '15000000000');
assert.equal(quote.usdtUsdE8, '100000000');
assert.equal(invoked, 1);
await assert.rejects(() => getStarsQuoteFromRpc({ solanaEndpoint: 'https://test.shineup.me/solana-rpc', solana,
connection: { getMultipleAccountsInfo: async () => [solPrice, null] }, nowSeconds: now }), /отсутствует/);
});
test('no server GetStarsQuote in active WS registry or UI', () => {
const reg = readFileSync(new URL('../../SHiNE-server/shine-server-net-protocol/src/main/java/server/logic/ws_protocol/JSON/JsonHandlerRegistry.java', import.meta.url), 'utf8');
const auth = readFileSync(new URL('../js/services/auth-service.js', import.meta.url), 'utf8');
assert.doesNotMatch(reg, /GetStarsQuote/);
assert.doesNotMatch(auth, /GetStarsQuote/);
for (const p of ['../js/components/shine-support-dialog.js', '../js/pages/channel-donate-view.js']) {
const s = readFileSync(new URL(p, import.meta.url), 'utf8');
assert.match(s, /getStarsQuoteFromRpc/);
assert.doesNotMatch(s, /authService\.getStarsQuote/);
}
});
+19
View File
@@ -0,0 +1,19 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { parseStarCents, formatStars, splitStarCents, starCentsToLamports } from '../js/services/shine-support-amount.js';
test('strictly two fractional digits, minimum 0.10 Stars', () => {
assert.equal(parseStarCents('0,10'), 10n);
assert.equal(parseStarCents('0.75'), 75n);
assert.equal(formatStars(75n), '0.75 ⭐');
assert.throws(() => parseStarCents('0.09'));
assert.throws(() => parseStarCents('0.001'));
});
test('DAO star share rounds UP to cents', () => {
assert.deepEqual(splitStarCents(10n), {author: 9n, dao: 1n});
assert.deepEqual(splitStarCents(15n), {author: 13n, dao: 2n});
assert.deepEqual(splitStarCents(75n), {author: 67n, dao: 8n});
});
test('quote works in integer lamports without floats', () => {
assert.equal(starCentsToLamports(75n, 150n * 100_000_000n, 100_000_000n), 5_000_000n);
assert.equal(starCentsToLamports(10n, 150n * 100_000_000n, 100_000_000n), 666_667n);
});
+7 -7
View File
@@ -5,10 +5,10 @@ import { supportStatsValues } from '../js/components/support-stats.js';
function file(path) { return readFileSync(new URL(path, import.meta.url), 'utf8'); }
test('three displayed counters: full sent, net received, sent/10 + direct', () => {
assert.deepEqual(supportStatsValues({ supportSent: 1_000_000_000n, supportReceived: 900_000_000n, daoDirect: 200_000_000n }), [1_000_000_000n, 900_000_000n, 300_000_000n]);
test('three displayed counters: sent, received, direct DAO in star cents', () => {
assert.deepEqual(supportStatsValues({ supportSent: 1_000_000_000n, supportReceived: 900_000_000n, daoDirect: 200_000_000n }), [1_000_000_000n, 900_000_000n, 200_000_000n]);
assert.deepEqual(supportStatsValues({}), [0n, 0n, 0n]);
assert.deepEqual(supportStatsValues({ supportSent: '10000000000000000000', supportReceived: '9000000000000000000', daoDirect: '250000000000000000' }), [10000000000000000000n, 9000000000000000000n, 1250000000000000000n]);
assert.deepEqual(supportStatsValues({ supportSent: '10000000000000000000', supportReceived: '9000000000000000000', daoDirect: '250000000000000000' }), [10000000000000000000n, 9000000000000000000n, 250000000000000000n]);
});
test('profile views attach counters from server cache and support user action', () => {
@@ -35,13 +35,13 @@ test('message buttons pass checked block hashes, not message text', () => {
}
});
test('shared modal protects direct and tracked workflows', () => {
test('shared modal requires Stars and oracle quote', () => {
const src = file('../js/components/shine-support-dialog.js');
assert.match(src, /supportShineUserOnSolana/);
assert.match(src, /supportShineDaoOnSolana/);
assert.match(src, /transferSolLamports/);
assert.match(src, /window\.confirm\(t\('screens\.support_phase2\.direct_warning'\)\)/);
assert.match(src, /amount % 10n/);
assert.match(src, /starCentsToLamports/);
assert.match(src, /getStarsQuoteFromRpc/);
assert.match(src, /parseStarCents/);
});
test('profile statistics use server API without Solana RPC', () => {