Skip to content

Commit 2cf202b

Browse files
authored
Merge pull request #891 from PhilippeR26/cairo240-string
Cairo 2.4.0 new types : bytes31 & ByteArray
2 parents 65e886b + 8ce3b1d commit 2cf202b

File tree

17 files changed

+6967
-13
lines changed

17 files changed

+6967
-13
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//Cairo 2.5.0
2+
3+
#[starknet::interface]
4+
trait ITestReject<TContractState> {
5+
fn proceed_bytes31(self: @TContractState, str: bytes31) -> bytes31;
6+
fn get_string(self: @TContractState) -> ByteArray;
7+
fn proceed_string(self: @TContractState, mess: ByteArray) -> ByteArray;
8+
}
9+
10+
#[starknet::contract]
11+
mod MyTestReject {
12+
use core::option::OptionTrait;
13+
use core::traits::TryInto;
14+
use core::bytes_31::Bytes31Trait;
15+
use core::byte_array::ByteArrayTrait;
16+
#[storage]
17+
struct Storage {}
18+
// To be tested with special characters (!@#$%^&*_+{}|:";./,\[];'<>?~`)
19+
#[abi(embed_v0)]
20+
impl TestReject of super::ITestReject<ContractState> {
21+
fn proceed_bytes31(self: @ContractState, str: bytes31) -> bytes31 {
22+
let mut mess: ByteArray = "Cairo has become the most popular language for developers!@#$%^&*_+|:'<>?~`";
23+
mess.append_byte(55_u8);
24+
str
25+
}
26+
27+
fn get_string(self: @ContractState) -> ByteArray {
28+
let mess: ByteArray = "Cairo has become the most popular language for developers" + " + charizards !@#$%^&*_+|:'<>?~`";
29+
mess
30+
}
31+
32+
fn proceed_string(self: @ContractState, mess: ByteArray) -> ByteArray {
33+
let mut res = mess;
34+
let add: ByteArray = " Zorg is back";
35+
res.append(@add);
36+
res
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)