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

Add test for Bravos transfer #721

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
Empty file added .multicall_compiled.json
Empty file.
31 changes: 31 additions & 0 deletions tests/cases/cairo_vm/contracts/multi_route_swap.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#[starknet::contract]
mod MultiCall {
use starknet::ContractAddress;
use core::debug::PrintTrait;
use core::integer::u256;
#[storage]
struct Storage {}

#[derive(Drop, Serde)]
pub struct Route {
pub to: ContractAddress,
pub selector: u256,
pub calldata: Span<felt252>
}

#[external(v0)]
fn multi_route_swap(
self: @ContractState,
token_from_address: ContractAddress,
token_from_amount: u256,
token_to_address: ContractAddress,
token_to_amount: u256,
token_to_min_amount: u256,
beneficiary: ContractAddress,
integrator_fee_amount_bps: u128,
integrator_fee_recipient: ContractAddress,
routes: Span<Route>,
) -> bool {
true
}
}
35 changes: 35 additions & 0 deletions tests/cases/cairo_vm/contracts/multicall.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#[starknet::contract]
mod MultiCall {
// use starknet::account::Call;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check in the issue,

In the multicall.cairo, there are some commented lines. If you change the type of calldata to Span, uncomment those lines and comment out the ones above so that it compiles.

Can we add the two cases of this contract with the two different data types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pefontana which is the other calldata's type you are refering to? Because its type was Span when I first saw it.

use starknet::ContractAddress;
use core::debug::PrintTrait;
use core::integer::u256;
#[storage]
struct Storage {}

#[derive(Drop, Serde)]
pub struct Call {
pub to: ContractAddress,
pub selector: u256,
pub calldata: Span<felt252>
}

#[external(v0)]
fn fib(self: @ContractState, calls: Span<Call>) -> felt252 {
let mut calls = calls;
loop {
match calls.pop_front() {
Option::Some(call) => {
println!("To {:?}", (*call.to));
println!("Selector {}", (*call.selector));
//println!("Call[0] {:?}", (*(*call.calldata).at(0)));
//println!("Call[0] {:?}", (*(*call.calldata).at(1)));
println!("Call[0] {:?}", (*(call.calldata)[0]));
println!("Call[1] {:?}", (*(call.calldata)[1]));
},
Option::None => { break; },
}
};
12
}
}
18 changes: 18 additions & 0 deletions tests/tests/cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,24 @@ fn test_program_cases(program_path: &str) {
#[test_case("tests/cases/cairo_vm/contracts/field_sqrt.cairo", &[])]
#[test_case("tests/cases/cairo_vm/contracts/random_ec_point.cairo", &[])]
#[test_case("tests/cases/cairo_vm/contracts/alloc_constant_size.cairo", &[10, 10, 10])]
#[test_case("tests/cases/cairo_vm/contracts/multicall.cairo", &[
// n_calls
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add in the commented lines what these numbers are?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further, maybe using the serialized bytes and include! results in something readable?

// params: 0: contract_address, 1: selector, rest: calldata
6,
// call 1
12, 17, 3, 2, 1, 2,
// call 2
13, 18, 4, 3, 1, 2, 3,
// call 3
17, 16, 5, 20, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
// call 4
17, 17, 0, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
// call 5
17, 17, 0, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
// call 6
17, 17, 0, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
])]
#[test_case("tests/cases/cairo_vm/contracts/multi_route_swap.cairo", &[1, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 0])]
fn test_contract_cases(program_path: &str, args: &[u128]) {
let args = args.iter().map(|&arg| arg.into()).collect_vec();

Expand Down
Loading