Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes #14

Merged
merged 9 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
};

await expect(
generateAbis([ds], PROJECT_PATH, undefined as any, undefined as any, undefined as any)

Check warning on line 40 in packages/common-starknet/src/codegen/codegen-controller.spec.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type

Check warning on line 40 in packages/common-starknet/src/codegen/codegen-controller.spec.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type

Check warning on line 40 in packages/common-starknet/src/codegen/codegen-controller.spec.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type
).rejects.toThrow(/Asset: "zkLend" not found in project/);
).rejects.toThrow('Error: Asset zkLend, file ./abis/xxx.json does not exist');
});

it('render correct codegen from ejs', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ import {
IBlock,
IStoreModelProvider,
} from '@subql/node-core';
import { StarknetBlock } from '@subql/types-starknet';
import {
StarknetProjectDs,
SubqueryProject,
} from '../../configure/SubqueryProject';
import { isFullBlock } from '../../starknet/block.starknet';
import { IndexerManager } from '../indexer.manager';
import { BlockContent, getBlockSize } from '../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,16 @@ describe('buildDictionaryV1QueryEntries', () => {
const result = buildDictionaryV1QueryEntries([ds]);

expect(result).toEqual([
[
{
conditions: [
{
field: 'type',
matcher: 'equalTo',
value: 'L1_HANDLER',
},
],
entity: 'calls',
},
],
{
conditions: [
{
field: 'type',
matcher: 'equalTo',
value: 'L1_HANDLER',
},
],
entity: 'calls',
},
]);
});

Expand Down
3 changes: 1 addition & 2 deletions packages/node/src/indexer/fetch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
IStoreModelProvider,
} from '@subql/node-core';
import { StarknetBlock, SubqlDatasource } from '@subql/types-starknet';
import { SubqueryProject } from '../configure/SubqueryProject';
import { StarknetApi } from '../starknet';
import {
calcInterval,
Expand Down Expand Up @@ -70,7 +69,7 @@ export class FetchService extends BaseFetchService<
}

protected async getBestHeight(): Promise<number> {
return (await this.getFinalizedHeader()).blockHeight;
return this.api.getBestBlockHeight();
}

// eslint-disable-next-line @typescript-eslint/require-await
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/indexer/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class ProjectService extends BaseProjectService<
protected async getBlockTimestamp(height: number): Promise<Date> {
const block = await this.apiService.unsafeApi.api.getBlock(height);

return new Date(block.timestamp * 1000); // TODO test and make sure its in MS not S
return new Date(block.timestamp * 1000);
}

protected onProjectChange(project: SubqueryProject): void | Promise<void> {
Expand Down
7 changes: 5 additions & 2 deletions packages/node/src/indexer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { isFullBlock } from '../starknet/block.starknet';
export type BlockContent = StarknetBlock | LightStarknetBlock;

export function getBlockSize(block: BlockContent): number {
// TODO. not sure if this is the right way to determine the block size
return isFullBlock(block) ? (block as StarknetBlock).transactions.length : 0;
return isFullBlock(block)
? block.transactions
.map((tx) => tx.receipt.execution_resources.steps)
.reduce((sum, steps) => sum + steps, 0)
: block.transactions.length;
}
4 changes: 1 addition & 3 deletions packages/node/src/indexer/unfinalizedBlocks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import { BlockContent } from './types';

@Injectable()
export class UnfinalizedBlocksService extends BaseUnfinalizedBlocksService<BlockContent> {
private supportsFinalization?: boolean;
private startupCheck = true;

constructor(
private readonly apiService: ApiService,
nodeConfig: NodeConfig,
Expand All @@ -38,6 +35,7 @@ export class UnfinalizedBlocksService extends BaseUnfinalizedBlocksService<Block

protected async getHeaderForHash(hash: string): Promise<Header> {
const block = await this.apiService.api.getBlockByHeightOrHash(hash);

return starknetBlockToHeader(formatBlock(block));
}

Expand Down
7 changes: 0 additions & 7 deletions packages/node/src/starknet/api.service.starknet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ describe('ApiService', () => {
).resolves.toHaveLength(4);
});

it('can fetch block events with height', async () => {
//https://starkscan.co/block/500000#events
await expect(apiService.api.fetchBlockLogs(500000)).resolves.toHaveLength(
637,
);
});

it('can get the finalized height', async () => {
const height = (await apiService.api.getFinalizedBlock()).block_number;

Expand Down
20 changes: 15 additions & 5 deletions packages/node/src/starknet/api.starknet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ describe('Api.starknet', () => {
blockData = await fetchBlock(979358);
});

it('should get finalized block and best block', async () => {
const finalized = await strkApi.getFinalizedBlock();
const best = await strkApi.getBestBlockHeight();

expect(finalized).toBeDefined();
expect(best).toBeDefined();

expect(best).toBeGreaterThan(finalized.block_number);
});

it('should get finalized block', async () => {
const finalized = await strkApi.getFinalizedBlock();
expect(finalized).toBeDefined();
Expand All @@ -71,18 +81,18 @@ describe('Api.starknet', () => {
expect(blockData.logs[0].transaction.calldata.length).toBeGreaterThan(1);
});

it('should have the ability to get receipts via transactions from all types', async () => {
expect(await blockData.transactions[0].receipt?.()).toBeDefined();
it('should have the ability to get receipts via transactions from all types', () => {
expect(blockData.transactions[0].receipt).toBeDefined();

expect(typeof blockData.transactions[0].receipt).toEqual('function');
expect(typeof blockData.logs[0].transaction.receipt).toEqual('function');
expect(typeof blockData.transactions[0].receipt).toEqual('object');
expect(typeof blockData.logs[0].transaction.receipt).toEqual('object');
expect(typeof blockData.logs[0].transaction.from).toEqual('string');
expect(typeof blockData.transactions[1].logs![0].transaction.from).toEqual(
'string',
);
expect(
typeof blockData.transactions[1].logs![0].transaction.receipt,
).toEqual('function');
).toEqual('object');
});

//https://starkscan.co/tx/0x0153a20567e66728f3c4ba60913a6011b9c73db9ea4d960e959923ed5afd8a24
Expand Down
Loading
Loading