Skip to content

Commit

Permalink
fix: fix multiple same events + add cairo code + seperate tests, lega…
Browse files Browse the repository at this point in the history
…cy and Cairo1
  • Loading branch information
edisontim committed Aug 7, 2023
1 parent 06498d5 commit 7c93157
Show file tree
Hide file tree
Showing 14 changed files with 11,333 additions and 14,493 deletions.
7,908 changes: 2,603 additions & 5,305 deletions __mocks__/cairo/helloCairo2/compiled.casm

Large diffs are not rendered by default.

14,147 changes: 8,423 additions & 5,724 deletions __mocks__/cairo/helloCairo2/compiled.json

Large diffs are not rendered by default.

92 changes: 92 additions & 0 deletions __mocks__/cairo/helloCairo2/hello.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ trait IHelloStarknet<TContractState> {
fn test_u128(self: @TContractState, p1: u128) -> u128;
fn test_u256(self: @TContractState, p1: u256) -> u256;

// event test
fn emitEventRegular(
ref self: TContractState,
simpleKeyVariable: u8,
simpleKeyStruct: HelloStarknet::SimpleStruct,
simpleKeyArray: Array<u8>,
simpleDataVariable: u8,
simpleDataStruct: HelloStarknet::SimpleStruct,
simpleDataArray: Array<u8>
);
fn emitEventNested(
ref self: TContractState,
nestedKeyStruct: HelloStarknet::NestedStruct,
nestedDataStruct: HelloStarknet::NestedStruct
);

// echo Array
fn echo_array(self: @TContractState, data: Array<u8>) -> Array<u8>;
fn echo_array_u256(self: @TContractState, data: Array<u256>) -> Array<u256>;
Expand Down Expand Up @@ -168,6 +184,45 @@ mod HelloStarknet {
user1: UserData,
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
EventRegular: EventRegular,
EventNested: EventNested,
}

#[derive(Drop, Serde)]
struct SimpleStruct {
first: u8,
second: u16,
}

#[derive(Drop, Serde)]
struct NestedStruct {
simpleStruct: SimpleStruct,
simpleArray: Array<u8>,
}

#[derive(Drop, starknet::Event)]
struct EventRegular {
#[key]
simpleKeyVariable: u8,
#[key]
simpleKeyStruct: SimpleStruct,
#[key]
simpleKeyArray: Array<u8>,
simpleDataVariable: u8,
simpleDataStruct: SimpleStruct,
simpleDataArray: Array<u8>,
}

#[derive(Drop, starknet::Event)]
struct EventNested {
#[key]
nestedKeyStruct: NestedStruct,
nestedDataStruct: NestedStruct,
}

#[l1_handler]
fn increase_bal(ref self: ContractState, from_address: felt252, amount: felt252) {
let current = self.balance.read();
Expand Down Expand Up @@ -238,6 +293,43 @@ mod HelloStarknet {
p1 + to_add
}

// event test
fn emitEventRegular(
ref self: ContractState,
simpleKeyVariable: u8,
simpleKeyStruct: SimpleStruct,
simpleKeyArray: Array<u8>,
simpleDataVariable: u8,
simpleDataStruct: SimpleStruct,
simpleDataArray: Array<u8>
) {
self
.emit(
Event::EventRegular(
EventRegular {
simpleKeyVariable: simpleKeyVariable,
simpleKeyStruct: simpleKeyStruct,
simpleKeyArray: simpleKeyArray,
simpleDataVariable: simpleDataVariable,
simpleDataStruct: simpleDataStruct,
simpleDataArray: simpleDataArray
}
)
);
}
fn emitEventNested(
ref self: ContractState, nestedKeyStruct: NestedStruct, nestedDataStruct: NestedStruct
) {
self
.emit(
Event::EventNested(
EventNested {
nestedKeyStruct: nestedKeyStruct, nestedDataStruct: nestedDataStruct,
}
)
)
}

// echo Array
fn echo_array(self: @ContractState, data: Array<u8>) -> Array<u8> {
data
Expand Down
Loading

0 comments on commit 7c93157

Please sign in to comment.