More cards
This commit is contained in:
+14
-5
@@ -15,6 +15,7 @@ import { NETWORK, CONSENSUS, blockClaimMessage, nftTransferMessage,
|
||||
type MiningTemplate, type NftTransfer, type TestnetBlock, type TestnetSnapshot } from '../shared/testnet.ts';
|
||||
|
||||
const root = fileURLToPath(new URL('../', import.meta.url));
|
||||
const wikipediaMock = resolve(root, 'tests', 'mock-wikipedia.mjs');
|
||||
const binary = resolve(process.env.RANDOMX_BINARY ?? join(root, 'native', 'build',
|
||||
`wikideck-randomx${process.platform === 'win32' ? '.exe' : ''}`));
|
||||
|
||||
@@ -74,7 +75,7 @@ test('native RandomX HTTP: three blocks, mined transfer, peer gossip/sync and du
|
||||
|
||||
async function start(dataDir: string, peer?: string): Promise<RunningNode> {
|
||||
t.signal.throwIfAborted();
|
||||
const child = spawn(process.execPath, ['--experimental-strip-types', 'server/index.ts'], {
|
||||
const child = spawn(process.execPath, ['--import', wikipediaMock, '--experimental-strip-types', 'server/index.ts'], {
|
||||
cwd: root, windowsHide: true, shell: false,
|
||||
env: { ...process.env, HOST: '127.0.0.1', PORT: '0', NODE_ENV: 'production',
|
||||
WIKIDECK_DATA_DIR: dataDir, RANDOMX_BINARY: binary,
|
||||
@@ -116,7 +117,7 @@ test('native RandomX HTTP: three blocks, mined transfer, peer gossip/sync and du
|
||||
headers: Record<string, string> = {}): Promise<Response> {
|
||||
const response = await fetch(`${base}${path}`, {
|
||||
method: body === undefined ? 'GET' : 'POST', redirect: 'error',
|
||||
signal: AbortSignal.any([t.signal, AbortSignal.timeout(15_000)]),
|
||||
signal: AbortSignal.any([t.signal, AbortSignal.timeout(30_000)]),
|
||||
headers: { ...(body === undefined ? {} : { 'Content-Type': 'application/json' }), ...headers },
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
});
|
||||
@@ -183,7 +184,7 @@ test('native RandomX HTTP: three blocks, mined transfer, peer gossip/sync and du
|
||||
assert.equal(health.headers.has('ratelimit'), false);
|
||||
await (await request(first.base, '/api/wikipedia/0', 400)).text();
|
||||
await (await request(first.base, '/api/wikipedia/not-a-page', 400)).text();
|
||||
await (await request(first.base, '/api/wikipedia/9999999999', 404)).text();
|
||||
await (await request(first.base, '/api/wikipedia/9999999999', 503)).text();
|
||||
const initial = await snapshot(first.base);
|
||||
assert.equal(initial.network, NETWORK);
|
||||
assert.equal(initial.chainId, CHAIN_ID);
|
||||
@@ -214,6 +215,12 @@ test('native RandomX HTTP: three blocks, mined transfer, peer gossip/sync and du
|
||||
|
||||
const block1 = await mine(first.base, alice);
|
||||
assert.equal(block1.height, 1);
|
||||
assert.equal(block1.article.source, 'live');
|
||||
assert.ok(block1.article.image);
|
||||
assert.ok(['https://upload.wikimedia.org', 'https://thumb.wikimedia.org'].includes(new URL(block1.article.image).origin));
|
||||
assert.equal(block1.statsSnapshot.pageviews.status, 'available');
|
||||
assert.equal(block1.statsSnapshot.pageviews.total, 600);
|
||||
assert.equal(block1.statsSnapshot.revisionId, block1.article.pageId + 1);
|
||||
await submit(first.base, block1);
|
||||
const unsigned = { network: NETWORK, chainId: CHAIN_ID, cardHash: block1.tokenId,
|
||||
from: alice.owner, to: bob.owner, sequence: 0 };
|
||||
@@ -280,7 +287,8 @@ test('native RandomX HTTP: three blocks, mined transfer, peer gossip/sync and du
|
||||
assert.match(replay.error, /owner\/sequence/i);
|
||||
assert.deepEqual(await json(node.base, `/api/nfts/${block1.tokenId}`), {
|
||||
network: NETWORK, chainId: CHAIN_ID, tokenId: block1.tokenId, owner: bob.owner, sequence: 1,
|
||||
blockHash: block1.hash, confirmations: 3, article: block1.article, stateRoot: block3.stateRoot,
|
||||
blockHash: block1.hash, confirmations: 3, article: block1.article,
|
||||
statsSnapshot: block1.statsSnapshot, stateRoot: block3.stateRoot,
|
||||
});
|
||||
const inventory = await json<{ blocks: TestnetBlock[]; next: null }>(node.base, '/p2p/blocks?offset=0');
|
||||
assert.deepEqual(inventory, { blocks: canonical.blocks, next: null });
|
||||
@@ -308,7 +316,8 @@ test('native RandomX HTTP: three blocks, mined transfer, peer gossip/sync and du
|
||||
assert.deepEqual(restored, { ...canonical, peers: 0 });
|
||||
assert.deepEqual(await json(first.base, `/api/nfts/${block1.tokenId}`), {
|
||||
network: NETWORK, chainId: CHAIN_ID, tokenId: block1.tokenId, owner: bob.owner, sequence: 1,
|
||||
blockHash: block1.hash, confirmations: 3, article: block1.article, stateRoot: block3.stateRoot,
|
||||
blockHash: block1.hash, confirmations: 3, article: block1.article,
|
||||
statsSnapshot: block1.statsSnapshot, stateRoot: block3.stateRoot,
|
||||
});
|
||||
assert.deepEqual(await json(first.base, '/api/blocks', 200, block3), { accepted: false, reorg: false });
|
||||
await (await request(first.base, '/api/transfer', 400, transfer)).text();
|
||||
|
||||
Reference in New Issue
Block a user