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: Nested events not handled #1140

Merged
merged 60 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
dd7e48b
test: eth signer
PhilippeR26 Feb 27, 2024
f02f11f
Merge remote-tracking branch 'upstream/develop' into ETHsignerContract
PhilippeR26 Feb 27, 2024
3599be0
test: move secp256k1Point tests in a dedicated test file
PhilippeR26 Mar 11, 2024
648e4d6
Merge branch 'develop' into ETHsignerContract
PhilippeR26 Mar 11, 2024
656ce42
Merge branch 'develop' into ETHsignerContract
PhilippeR26 Mar 18, 2024
57d395b
feat: helper for transaction receipt
PhilippeR26 Mar 18, 2024
495512a
simplify extends for account class
gregoryguillou Mar 18, 2024
9365063
feat: handling of cairo u512 type
PhilippeR26 Mar 19, 2024
b4ea22a
Merge pull request #1021 from 0xknwn/feature/simplify-default-account…
tabaktoni Mar 19, 2024
ce13ede
refactor: change name of variable : GetTxReceiptResponseWithoutHelper
PhilippeR26 Mar 19, 2024
9f13a49
Merge branch 'develop' into txResponse3
PhilippeR26 Mar 20, 2024
d122e34
Merge branch 'develop' into ETHsignerContract
PhilippeR26 Mar 20, 2024
c7ca4e2
Merge branch 'develop' into u512
PhilippeR26 Mar 20, 2024
f273e70
fix: double lines for same imports
PhilippeR26 Mar 20, 2024
c98fae4
Merge branch 'develop' into next-version
tabaktoni Mar 22, 2024
24f82d4
fix: solve an error in validate.ts initiated by pr 1007
PhilippeR26 Mar 22, 2024
46ca53b
fix: correction of a word in guide
PhilippeR26 Mar 22, 2024
2262b5e
docs: validateChecksumAddress
ivpavici Mar 22, 2024
218632b
fix: jsdoc correction
PhilippeR26 Mar 22, 2024
6623ea5
Merge pull request #1022 from PhilippeR26/u512
tabaktoni Mar 22, 2024
60674d8
Merge pull request #1032 from starknet-io/ivpavici_1031
tabaktoni Mar 22, 2024
aefe139
docs: add tsdoc in utils/address.ts
PhilippeR26 Mar 22, 2024
ad6c552
Merge pull request #1034 from PhilippeR26/addAddressPaddingDoc
tabaktoni Mar 25, 2024
9847c88
test: add extra fees
PhilippeR26 Mar 25, 2024
8c10c4a
fix: estimateFeeBulk include skipValidate in accountInvocationsFactory
tabaktoni Mar 25, 2024
9610f2a
Merge pull request #1037 from starknet-io/fix/estimateFeeBulk-skipVal…
tabaktoni Mar 25, 2024
878ba0d
Merge branch 'next-version' into ETHsignerContract
tabaktoni Mar 25, 2024
ab9fbb8
Merge pull request #985 from PhilippeR26/ETHsignerContract
tabaktoni Mar 25, 2024
b656443
Merge pull request #1020 from PhilippeR26/txResponse3
tabaktoni Mar 25, 2024
587d9f6
feat: add type guard to receipt response status methods
tabaktoni Mar 25, 2024
9341385
fix: repair i128 typed data encoding and add typed data range checks
penovicp Mar 15, 2024
87147d5
chore: update left over StarkNet casing
penovicp Mar 15, 2024
4b2398a
Merge pull request #1038 from starknet-io/fix-transaction-receipt-suc…
tabaktoni Mar 25, 2024
e5c2b45
Merge branch 'develop' into next-version
tabaktoni Mar 26, 2024
99921b1
feat: bundle resolution, module, type import for walletacc
tabaktoni Mar 26, 2024
5265995
fix: estimateMessageFee - eth address format (#1040)
PhilippeR26 Mar 27, 2024
f121a75
docs: small guides cleanup (#1048)
ivpavici Mar 28, 2024
73e9bbf
fix(RpcProvider): allow client to provide `specVersion` in 0.7 provider
avimak Apr 1, 2024
2cf8ca0
fix: remove abis parameter from signer and account execute
PhilippeR26 Apr 1, 2024
80d7fa8
feat: configure u512 and Secp256k1Point for abiwan
haroune-mohammedi Mar 27, 2024
4b83943
chore: bump dependencies
penovicp Apr 1, 2024
abf87d1
chore: expose data gas consumed and data gas price for 0.7 rpc
dhruvkelawala Apr 2, 2024
d002bae
test: Improve tests performance (#1121)
lukasaric May 6, 2024
37526cf
Update _test.yml (#1126)
ivpavici May 15, 2024
fe24214
Merge pull request #1110 from starknet-io/next-version
tabaktoni May 21, 2024
66a5c03
chore(release): 6.9.0 [skip ci]
semantic-release-bot May 21, 2024
c9fab45
fix: handling of events nested in Cairo components
PhilippeR26 May 30, 2024
e16d245
fix: change names of events in tests
PhilippeR26 May 31, 2024
8c87f99
refactor: change type names
PhilippeR26 Jun 3, 2024
49554a2
test: adapt parseUDCEvent to events namespace
PhilippeR26 Jun 3, 2024
b01893c
refactor: implement reviewer requests
PhilippeR26 Jun 5, 2024
7702d9c
refactor: add spec6 types
PhilippeR26 Jun 6, 2024
4c65e9b
Merge branch 'next-version' into nested-events
PhilippeR26 Jun 6, 2024
3954420
Revert "Merge branch 'next-version' into nested-events"
PhilippeR26 Jun 6, 2024
73aaa34
Merge remote-tracking branch 'starknet-io/next-version' into nested-e…
PhilippeR26 Jun 6, 2024
7c3c1a2
fix: remove events.ts that came back after merge
PhilippeR26 Jun 6, 2024
ee3d2a3
Merge remote-tracking branch 'starknet-io/next-version' into nested-e…
PhilippeR26 Jun 7, 2024
b46a132
Merge remote-tracking branch 'starknet-io/next-version' into nested-e…
PhilippeR26 Jun 10, 2024
c077329
refactor: use of external types-js lib for events types
PhilippeR26 Jun 10, 2024
6dcdb51
Merge branch 'next-version' into nested-events
tabaktoni Jun 11, 2024
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
2,243 changes: 2,243 additions & 0 deletions __mocks__/cairo/cairo260/nestedEvents.abi.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
constants,
contractClassResponseToLegacyCompiledContract,
ec,
events,
extractContractHashes,
hash,
num,
parseUDCEvent,
shortString,
stark,
} from '../src';
Expand Down Expand Up @@ -537,7 +537,7 @@ describe('deploy and test Wallet', () => {

// check pre-calculated address
const txReceipt = await provider.waitForTransaction(deployment.transaction_hash);
const udcEvent = parseUDCEvent(txReceipt as any); // todo: when time fix types
const udcEvent = events.parseUDCEvent(txReceipt as any); // todo: when time fix types
expect(cleanHex(deployment.contract_address[0])).toBe(cleanHex(udcEvent.contract_address));
});

Expand All @@ -558,7 +558,7 @@ describe('deploy and test Wallet', () => {

// check pre-calculated address
const txReceipt = await provider.waitForTransaction(deployment.transaction_hash);
const udcEvent = parseUDCEvent(txReceipt as any); // todo: when time fix types
const udcEvent = events.parseUDCEvent(txReceipt as any); // todo: when time fix types
expect(cleanHex(deployment.contract_address[0])).toBe(cleanHex(udcEvent.contract_address));
});

Expand Down
194 changes: 180 additions & 14 deletions __tests__/cairo1v2.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import fs from 'node:fs';
import path from 'node:path';
import {
Account,
BigNumberish,
Expand All @@ -18,7 +20,9 @@ import {
byteArray,
cairo,
ec,
events,
hash,
json,
num,
selector,
shortString,
Expand Down Expand Up @@ -870,7 +874,7 @@ describe('Cairo 1', () => {
);
const shouldBe: types.ParsedEvents = [
{
EventRegular: {
'hello_res_events_newTypes::hello_res_events_newTypes::HelloStarknet::EventRegular': {
simpleKeyVariable,
simpleKeyStruct,
simpleKeyArray,
Expand All @@ -881,8 +885,8 @@ describe('Cairo 1', () => {
},
];
const tx = await provider.waitForTransaction(transaction_hash);
const events = eventContract.parseEvents(tx);
return expect(events).toStrictEqual(shouldBe);
const myEvents = eventContract.parseEvents(tx);
return expect(myEvents).toStrictEqual(shouldBe);
});

test('parse event returning a nested struct', async () => {
Expand All @@ -892,22 +896,22 @@ describe('Cairo 1', () => {
);
const shouldBe: types.ParsedEvents = [
{
EventNested: {
'hello_res_events_newTypes::hello_res_events_newTypes::HelloStarknet::EventNested': {
nestedKeyStruct,
nestedDataStruct,
},
},
];
const tx = await provider.waitForTransaction(transaction_hash);
const events = eventContract.parseEvents(tx);
return expect(events).toStrictEqual(shouldBe);
const myEvents = eventContract.parseEvents(tx);
return expect(myEvents).toStrictEqual(shouldBe);
});

test('parse tx returning multiple similar events', async () => {
const anotherKeyVariable = 100n;
const shouldBe: types.ParsedEvents = [
{
EventRegular: {
'hello_res_events_newTypes::hello_res_events_newTypes::HelloStarknet::EventRegular': {
simpleKeyVariable,
simpleKeyStruct,
simpleKeyArray,
Expand All @@ -917,7 +921,7 @@ describe('Cairo 1', () => {
},
},
{
EventRegular: {
'hello_res_events_newTypes::hello_res_events_newTypes::HelloStarknet::EventRegular': {
simpleKeyVariable: anotherKeyVariable,
simpleKeyStruct,
simpleKeyArray,
Expand Down Expand Up @@ -945,13 +949,13 @@ describe('Cairo 1', () => {
]);
const { transaction_hash } = await account.execute([callData1, callData2]);
const tx = await provider.waitForTransaction(transaction_hash);
const events = eventContract.parseEvents(tx);
return expect(events).toStrictEqual(shouldBe);
const myEvents = eventContract.parseEvents(tx);
return expect(myEvents).toStrictEqual(shouldBe);
});
test('parse tx returning multiple different events', async () => {
const shouldBe: types.ParsedEvents = [
{
EventRegular: {
'hello_res_events_newTypes::hello_res_events_newTypes::HelloStarknet::EventRegular': {
simpleKeyVariable,
simpleKeyStruct,
simpleKeyArray,
Expand All @@ -961,7 +965,7 @@ describe('Cairo 1', () => {
},
},
{
EventNested: {
'hello_res_events_newTypes::hello_res_events_newTypes::HelloStarknet::EventNested': {
nestedKeyStruct,
nestedDataStruct,
},
Expand All @@ -981,8 +985,170 @@ describe('Cairo 1', () => {
]);
const { transaction_hash } = await account.execute([callData1, callData2]);
const tx = await provider.waitForTransaction(transaction_hash);
const events = eventContract.parseEvents(tx);
return expect(events).toStrictEqual(shouldBe);
const myEvents = eventContract.parseEvents(tx);
return expect(myEvents).toStrictEqual(shouldBe);
});

test('parsing nested events from Cairo components', () => {
// this abi is from Sepolia contract 0x07981ea76ca241100a3e1cd4083a15a73a068b6d6a946d36042cbfc9b531baa2
// with the end from OpenZeppelin ERC20 contract (for `flat` event test)
const { abi } = json.parse(
fs
.readFileSync(
path.resolve(__dirname, `../__mocks__/cairo/cairo260/nestedEvents.abi.json`)
)
.toString('ascii')
);
const abiEvents = events.getAbiEvents(abi);
const abiStructs = CallData.getAbiStruct(abi);
const abiEnums = CallData.getAbiEnum(abi);
const rawEventNested = {
block_hash: '0x39f27ab4cd508ab99e818512b261a7e4ae01072eb4ec8bb86aeb64755f99f2c',
block_number: 69198,
data: [
'0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
'0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d',
'0x0',
'0x0',
'0x8bb2c97000',
'0x0',
'0x425615c73f000',
'0x0',
'0x0',
'0x0',
'0x0',
'0x2bfc41e4bcfdbe82d0bafe3f935dadb18b6e90be3d22ccccea1f5b10986ed53',
'0x7aab02decaf82af6fa798fe8d23de042695846ab9dae9f18331fffc518d3d36',
'0x616b697261',
'0x616b697261',
],
from_address: '0x7981ea76ca241100a3e1cd4083a15a73a068b6d6a946d36042cbfc9b531baa2',
keys: [
'0x22ea134d4126804c60797e633195f8c9aa5fd6d1567e299f4961d0e96f373ee',
'0x2e0a012a863e6b614014d113e7285b06e30d2999e42e6e03ba2ef6158b0a8f1',
'0x33e29bc9b537bae4e370559331e2bf35b434b566f41a64601b37f410f46a580',
'0x33e29bc9b537bae4e370559331e2bf35b434b566f41a64601b37f410f46a580',
],
transaction_hash: '0x4e38fcce79c115b6fe2c486e3514efc1bd4da386b91c104e97230177d0bf181',
};
const parsedEvent = events.parseEvents([rawEventNested], abiEvents, abiStructs, abiEnums);
expect(parsedEvent).toEqual([
{
'kurosawa_akira::ExchangeBalanceComponent::exchange_balance_logic_component::Trade': {
maker: 1466771120193999006693452314154095230636738457276435850562375218974960297344n,
taker: 1466771120193999006693452314154095230636738457276435850562375218974960297344n,
ticker: {
'0': 2087021424722619777119509474943472645767659996348769578120564519014510906823n,
'1': 2009894490435840142178314390393166646092438090257831307886760648929397478285n,
},
router_maker: 0n,
router_taker: 0n,
amount_base: 600000000000n,
amount_quote: 1167000000000000n,
is_sell_side: false,
is_failed: false,
is_ecosystem_book: false,
maker_hash:
1243447045605505261525562127352132336915826038411731622093247599150671261011n,
taker_hash:
3467769886575726876986429904727435956490031836678599158998056330580017888566n,
maker_source: 418413900385n,
taker_source: 418413900385n,
},
},
]);
// From component `DepositComponent`, event `Deposit` (same event name than next)
const rawEventNestedDeposit1 = {
block_hash: '0x31afd649a5042cb1855ce820708a555eab62fe6ea07a2a538fa9100cdc80383',
block_number: 69198,
data: [
'0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
'0x33e29bc9b537bae4e370559331e2bf35b434b566f41a64601b37f410f46a580',
'0x119b74ab81c000',
'0x0',
],
from_address: '0x7981ea76ca241100a3e1cd4083a15a73a068b6d6a946d36042cbfc9b531baa2',
keys: [
'0xa1db419bdf20c7726cf74c30394c4300e5645db4e3cacaf897da05faabae03',
'0x9149d2123147c5f43d258257fef0b7b969db78269369ebcf5ebb9eef8592f2',
'0x033e29bc9b537bae4e370559331e2bf35b434b566f41a64601b37f410f46a580',
],
transaction_hash: '0x7768860d79bfb4c8463d215abea3c267899e373407c6882077f7447051c50de',
};
// From component `RouterComponent`, event `Deposit` (same event name than previous)
const rawEventNestedDeposit2 = {
block_hash: '0x39f27ab4cd508ab99e818512b261a7e4ae01072eb4ec8bb86aeb64755f99f2c',
block_number: 69198,
data: [
'0x33e29bc9b537bae4e370559331e2bf35b434b566f41a64601b37f410f46a580',
'0x119b74ab81c000',
'0x0',
],
from_address: '0x7981ea76ca241100a3e1cd4083a15a73a068b6d6a946d36042cbfc9b531baa2',
keys: [
'0x1352a17d221f274db15a49e35cc827e5106495ba85330b210632597411d5a46',
'0x9149d2123147c5f43d258257fef0b7b969db78269369ebcf5ebb9eef8592f2',
'0x33e29bc9b537bae4e370559331e2bf35b434b566f41a64601b37f410f46a580',
'0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
],
transaction_hash: '0x2d5210e5334a83306abe6f7f5e7e65cd1feed72ad3b8e359a2f4614fa948e1d',
};
const parsedEventNestedDeposit1 = events.parseEvents(
[rawEventNestedDeposit1],
abiEvents,
abiStructs,
abiEnums
);
expect(parsedEventNestedDeposit1).toEqual([
{
'kurosawa_akira::DepositComponent::deposit_component::Deposit': {
receiver: 1466771120193999006693452314154095230636738457276435850562375218974960297344n,
token: 2087021424722619777119509474943472645767659996348769578120564519014510906823n,
funder: 1466771120193999006693452314154095230636738457276435850562375218974960297344n,
amount: 4956000000000000n,
},
},
]);
const parsedEventNestedDeposit2 = events.parseEvents(
[rawEventNestedDeposit2],
abiEvents,
abiStructs,
abiEnums
);
expect(parsedEventNestedDeposit2).toEqual([
{
'kurosawa_akira::RouterComponent::router_component::Deposit': {
router: 1466771120193999006693452314154095230636738457276435850562375218974960297344n,
token: 2087021424722619777119509474943472645767659996348769578120564519014510906823n,
funder: 1466771120193999006693452314154095230636738457276435850562375218974960297344n,
amount: 4956000000000000n,
},
},
]);

// parsing nested event with #[flat] attribute, from a Cairo component
const rawEventFlat = {
block_hash: '0x39f27ab4cd508ab99e818512b261a7e4ae01072eb4ec8bb86aeb64755f99f2c',
block_number: 69198,
data: ['0x119b74ab81c000', '0x0'],
from_address: '0x7981ea76ca241100a3e1cd4083a15a73a068b6d6a946d36042cbfc9b531baa2',
keys: [
'0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9',
'0x33e29bc9b537bae4e370559331e2bf35b434b566f41a64601b37f410f46a580',
'0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
],
transaction_hash: '0x2da31a929a9848e9630906275a75a531e1718d4830501e10b0bccacd55f6fe0',
};
const parsedEventFlat = events.parseEvents([rawEventFlat], abiEvents, abiStructs, abiEnums);
expect(parsedEventFlat).toEqual([
{
'openzeppelin::token::erc20::erc20::ERC20Component::Transfer': {
from: 1466771120193999006693452314154095230636738457276435850562375218974960297344n,
to: 2087021424722619777119509474943472645767659996348769578120564519014510906823n,
value: 4956000000000000n,
},
},
]);
});
});

Expand Down
12 changes: 6 additions & 6 deletions __tests__/cairo1v2_typed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ describe('Cairo 1', () => {
);
const shouldBe: types.ParsedEvents = [
{
EventRegular: {
'hello_res_events_newTypes::hello_res_events_newTypes::HelloStarknet::EventRegular': {
simpleKeyVariable,
simpleKeyStruct,
simpleKeyArray,
Expand All @@ -824,7 +824,7 @@ describe('Cairo 1', () => {
);
const shouldBe: types.ParsedEvents = [
{
EventNested: {
'hello_res_events_newTypes::hello_res_events_newTypes::HelloStarknet::EventNested': {
nestedKeyStruct,
nestedDataStruct,
},
Expand All @@ -840,7 +840,7 @@ describe('Cairo 1', () => {
const anotherKeyVariable = 100n;
const shouldBe: types.ParsedEvents = [
{
EventRegular: {
'hello_res_events_newTypes::hello_res_events_newTypes::HelloStarknet::EventRegular': {
simpleKeyVariable,
simpleKeyStruct,
simpleKeyArray,
Expand All @@ -850,7 +850,7 @@ describe('Cairo 1', () => {
},
},
{
EventRegular: {
'hello_res_events_newTypes::hello_res_events_newTypes::HelloStarknet::EventRegular': {
simpleKeyVariable: anotherKeyVariable,
simpleKeyStruct,
simpleKeyArray,
Expand Down Expand Up @@ -884,7 +884,7 @@ describe('Cairo 1', () => {
test('parse tx returning multiple different events', async () => {
const shouldBe: types.ParsedEvents = [
{
EventRegular: {
'hello_res_events_newTypes::hello_res_events_newTypes::HelloStarknet::EventRegular': {
simpleKeyVariable,
simpleKeyStruct,
simpleKeyArray,
Expand All @@ -894,7 +894,7 @@ describe('Cairo 1', () => {
},
},
{
EventNested: {
'hello_res_events_newTypes::hello_res_events_newTypes::HelloStarknet::EventNested': {
nestedKeyStruct,
nestedDataStruct,
},
Expand Down
4 changes: 2 additions & 2 deletions src/contract/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
ParsedEvents,
RawArgs,
Result,
StructAbi,
AbiStruct,
ValidateType,
} from '../types';
import assert from '../utils/assert';
Expand Down Expand Up @@ -124,7 +124,7 @@ export class Contract implements ContractInterface {

deployTransactionHash?: string;

protected readonly structs: { [name: string]: StructAbi };
protected readonly structs: { [name: string]: AbiStruct };

protected readonly events: AbiEvents;

Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export * as ec from './utils/ec';
export * as starknetId from './utils/starknetId';
export * as provider from './utils/provider';
export * as selector from './utils/hash/selector';
export * as events from './utils/events/index';
export * as events from './utils/events';
export * from './utils/responseParser';
export * from './utils/cairoDataTypes/uint256';
export * from './utils/cairoDataTypes/uint512';
Expand All @@ -42,7 +42,6 @@ export * from './utils/url';
export * from './utils/calldata';
export * from './utils/calldata/enum';
export * from './utils/contract';
export * from './utils/events';
export * from './utils/transactionReceipt';
export * as wallet from './wallet/connect';

Expand Down
Loading