From c8ba40afd7c44d51c3970f0a00dbae93654069d6 Mon Sep 17 00:00:00 2001 From: gaetbout Date: Fri, 12 Apr 2024 15:05:38 +0200 Subject: [PATCH] remove pub on bytes data --- src/bytes/src/bytes.cairo | 16 +- src/bytes/src/lib.cairo | 2 +- src/bytes/src/tests/test_bytes.cairo | 188 +++++++++++------------ src/encoding/src/sol_abi/encode_as.cairo | 4 +- src/encoding/src/tests/sol_abi.cairo | 3 - 5 files changed, 112 insertions(+), 101 deletions(-) diff --git a/src/bytes/src/bytes.cairo b/src/bytes/src/bytes.cairo index b608b7e4..271b8aaf 100644 --- a/src/bytes/src/bytes.cairo +++ b/src/bytes/src/bytes.cairo @@ -34,9 +34,16 @@ const BYTES_PER_ELEMENT: usize = 16; #[derive(Drop, Clone, PartialEq, Serde)] pub struct Bytes { size: usize, - pub data: Array // TODO should this be pub? + data: Array } +pub impl BytesIndex of IndexView { + fn index(self: @Bytes, index: usize) -> @u128 { + self.data[index] + } +} + + pub trait BytesTrait { /// Create a Bytes from an array of u128 fn new(size: usize, data: Array) -> Bytes; @@ -48,6 +55,8 @@ pub trait BytesTrait { fn locate(offset: usize) -> (usize, usize); /// Get Bytes size fn size(self: @Bytes) -> usize; + /// Get data + fn data(self: Bytes) -> Array; /// update specific value (1 bytes) at specific offset fn update_at(ref self: Bytes, offset: usize, value: u8); /// Read value with size bytes from Bytes, and packed into u128 @@ -158,6 +167,11 @@ impl BytesImpl of BytesTrait { *self.size } + + fn data(self: Bytes) -> Array { + self.data + } + /// update specific value (1 bytes) at specific offset fn update_at(ref self: Bytes, offset: usize, value: u8) { assert(offset < self.size(), 'update out of bound'); diff --git a/src/bytes/src/lib.cairo b/src/bytes/src/lib.cairo index 8903b420..2e163f48 100644 --- a/src/bytes/src/lib.cairo +++ b/src/bytes/src/lib.cairo @@ -4,4 +4,4 @@ pub mod bytes; mod tests; pub mod utils; -pub use bytes::{Bytes, BytesTrait}; +pub use bytes::{Bytes, BytesTrait, BytesIndex}; diff --git a/src/bytes/src/tests/test_bytes.cairo b/src/bytes/src/tests/test_bytes.cairo index 224bb822..aca7edf9 100644 --- a/src/bytes/src/tests/test_bytes.cairo +++ b/src/bytes/src/tests/test_bytes.cairo @@ -1,5 +1,5 @@ use alexandria_bytes::utils::{BytesDebug, BytesDisplay}; -use alexandria_bytes::{Bytes, BytesTrait}; +use alexandria_bytes::{Bytes, BytesTrait, BytesIndex}; use starknet::ContractAddress; #[test] @@ -7,12 +7,12 @@ use starknet::ContractAddress; fn test_bytes_zero() { let bytes = BytesTrait::zero(1); assert_eq!(bytes.size(), 1, "invalid size"); - assert_eq!(*bytes.data[0], 0, "invalid value"); + assert_eq!(*bytes[0], 0, "invalid value"); let bytes = BytesTrait::zero(17); assert_eq!(bytes.size(), 17, "invalid size"); - assert_eq!(*bytes.data[0], 0, "invalid value"); - assert_eq!(*bytes.data[1], 0, "invalid value"); + assert_eq!(*bytes[0], 0, "invalid value"); + assert_eq!(*bytes[1], 0, "invalid value"); let (_, value) = bytes.read_u8(15); assert_eq!(value, 0, "invalid value"); let (_, value) = bytes.read_u8(0); @@ -36,23 +36,23 @@ fn test_bytes_update() { bytes.update_at(0, 0x05); assert_eq!(bytes.size(), 5, "update_size1"); - assert_eq!(*bytes.data[0], 0x05020304050000000000000000000000, "update_value_1"); + assert_eq!(*bytes[0], 0x05020304050000000000000000000000, "update_value_1"); bytes.update_at(1, 0x06); assert_eq!(bytes.size(), 5, "update_size2"); - assert_eq!(*bytes.data[0], 0x05060304050000000000000000000000, "update_value_2"); + assert_eq!(*bytes[0], 0x05060304050000000000000000000000, "update_value_2"); bytes.update_at(2, 0x07); assert_eq!(bytes.size(), 5, "update_size3"); - assert_eq!(*bytes.data[0], 0x05060704050000000000000000000000, "update_value_3"); + assert_eq!(*bytes[0], 0x05060704050000000000000000000000, "update_value_3"); bytes.update_at(3, 0x08); assert_eq!(bytes.size(), 5, "update_size4"); - assert_eq!(*bytes.data[0], 0x05060708050000000000000000000000, "update_value_4"); + assert_eq!(*bytes[0], 0x05060708050000000000000000000000, "update_value_4"); bytes.update_at(4, 0x09); assert_eq!(bytes.size(), 5, "update_size5"); - assert_eq!(*bytes.data[0], 0x05060708090000000000000000000000, "update_value_5"); + assert_eq!(*bytes[0], 0x05060708090000000000000000000000, "update_value_5"); let mut bytes = BytesTrait::new( 42, @@ -65,15 +65,15 @@ fn test_bytes_update() { bytes.update_at(16, 0x16); assert_eq!(bytes.size(), 42, "update_size6"); - assert_eq!(*bytes.data[0], 0x01020304050607080910111213141516, "update_value_6"); - assert_eq!(*bytes.data[1], 0x16020304050607080910111213141516, "update_value_7"); - assert_eq!(*bytes.data[2], 0x01020304050607080910000000000000, "update_value_8"); + assert_eq!(*bytes[0], 0x01020304050607080910111213141516, "update_value_6"); + assert_eq!(*bytes[1], 0x16020304050607080910111213141516, "update_value_7"); + assert_eq!(*bytes[2], 0x01020304050607080910000000000000, "update_value_8"); bytes.update_at(15, 0x01); assert_eq!(bytes.size(), 42, "update_size7"); - assert_eq!(*bytes.data[0], 0x01020304050607080910111213141501, "update_value_9"); - assert_eq!(*bytes.data[1], 0x16020304050607080910111213141516, "update_value_10"); - assert_eq!(*bytes.data[2], 0x01020304050607080910000000000000, "update_value_11"); + assert_eq!(*bytes[0], 0x01020304050607080910111213141501, "update_value_9"); + assert_eq!(*bytes[1], 0x16020304050607080910111213141516, "update_value_10"); + assert_eq!(*bytes[2], 0x01020304050607080910000000000000, "update_value_11"); } #[test] @@ -419,7 +419,7 @@ fn test_bytes_read_bytes() { let bytes = BytesTrait::new(46, array); let (new_offset, sub_bytes) = bytes.read_bytes(4, 37); - let sub_bytes_data = @sub_bytes.data; + let sub_bytes_data = @sub_bytes; assert_eq!(new_offset, 41, "read_bytes_offset"); assert_eq!(sub_bytes.size(), 37, "read_bytes_size"); assert_eq!(*sub_bytes_data[0], 0x05060708091011121314015401855d77, "read_bytes_value_1"); @@ -427,21 +427,21 @@ fn test_bytes_read_bytes() { assert_eq!(*sub_bytes_data[2], 0x6c2e0e04e10000000000000000000000, "read_bytes_value_3"); let (new_offset, sub_bytes) = bytes.read_bytes(0, 14); - let sub_bytes_data = @sub_bytes.data; + let sub_bytes_data = @sub_bytes; assert_eq!(new_offset, 14, "read_bytes_offset"); assert_eq!(sub_bytes.size(), 14, "read_bytes_size"); assert_eq!(*sub_bytes_data[0], 0x01020304050607080910111213140000, "read_bytes_value_4"); // read first byte let (new_offset, sub_bytes) = bytes.read_bytes(0, 1); - let sub_bytes_data = @sub_bytes.data; + let sub_bytes_data = @sub_bytes; assert_eq!(new_offset, 1, "read_bytes_offset"); assert_eq!(sub_bytes.size(), 1, "read_bytes_size"); assert_eq!(*sub_bytes_data[0], 0x01000000000000000000000000000000, "read_bytes_value_5"); // read last byte let (new_offset, sub_bytes) = bytes.read_bytes(45, 1); - let sub_bytes_data = @sub_bytes.data; + let sub_bytes_data = @sub_bytes; assert_eq!(new_offset, 46, "read_bytes_offset"); assert_eq!(sub_bytes.size(), 1, "read_bytes_size"); assert_eq!(*sub_bytes_data[0], 0x4f000000000000000000000000000000, "read_bytes_value_6"); @@ -455,70 +455,70 @@ fn test_bytes_append() { // append_u128_packed bytes.append_u128_packed(0x101112131415161718, 9); assert_eq!(bytes.size(), 9, "append_u128_packed_1_size"); - assert_eq!(*bytes.data[0], 0x10111213141516171800000000000000, "append_u128_packed_1_value_1"); - bytes = BytesTrait::new(bytes.size(), bytes.data); + assert_eq!(*bytes[0], 0x10111213141516171800000000000000, "append_u128_packed_1_value_1"); + bytes = BytesTrait::new(bytes.size(), bytes.data()); bytes.append_u128_packed(0x101112131415161718, 9); assert_eq!(bytes.size(), 18, "append_u128_packed_2_size"); - assert_eq!(*bytes.data[0], 0x10111213141516171810111213141516, "append_u128_packed_2_value_1"); - assert_eq!(*bytes.data[1], 0x17180000000000000000000000000000, "append_u128_packed_2_value_2"); - bytes = BytesTrait::new(bytes.size(), bytes.data); + assert_eq!(*bytes[0], 0x10111213141516171810111213141516, "append_u128_packed_2_value_1"); + assert_eq!(*bytes[1], 0x17180000000000000000000000000000, "append_u128_packed_2_value_2"); + bytes = BytesTrait::new(bytes.size(), bytes.data()); // append_u8 bytes.append_u8(0x01); assert_eq!(bytes.size(), 19, "append_u8_size"); - assert_eq!(*bytes.data[0], 0x10111213141516171810111213141516, "append_u8_value_1"); - assert_eq!(*bytes.data[1], 0x17180100000000000000000000000000, "append_u8_value_2"); - bytes = BytesTrait::new(bytes.size(), bytes.data); + assert_eq!(*bytes[0], 0x10111213141516171810111213141516, "append_u8_value_1"); + assert_eq!(*bytes[1], 0x17180100000000000000000000000000, "append_u8_value_2"); + bytes = BytesTrait::new(bytes.size(), bytes.data()); // append_u16 bytes.append_u16(0x0102); assert_eq!(bytes.size(), 21, "append_u16_size"); - assert_eq!(*bytes.data[0], 0x10111213141516171810111213141516, "append_u16_value_1"); - assert_eq!(*bytes.data[1], 0x17180101020000000000000000000000, "append_u16_value_2"); - bytes = BytesTrait::new(bytes.size(), bytes.data); + assert_eq!(*bytes[0], 0x10111213141516171810111213141516, "append_u16_value_1"); + assert_eq!(*bytes[1], 0x17180101020000000000000000000000, "append_u16_value_2"); + bytes = BytesTrait::new(bytes.size(), bytes.data()); // append_u32 bytes.append_u32(0x01020304); assert_eq!(bytes.size(), 25, "append_u32_size"); - assert_eq!(*bytes.data[0], 0x10111213141516171810111213141516, "append_u32_value_1"); - assert_eq!(*bytes.data[1], 0x17180101020102030400000000000000, "append_u32_value_2"); - bytes = BytesTrait::new(bytes.size(), bytes.data); + assert_eq!(*bytes[0], 0x10111213141516171810111213141516, "append_u32_value_1"); + assert_eq!(*bytes[1], 0x17180101020102030400000000000000, "append_u32_value_2"); + bytes = BytesTrait::new(bytes.size(), bytes.data()); // append_usize bytes.append_usize(0x01); assert_eq!(bytes.size(), 29, "append_usize_size"); - assert_eq!(*bytes.data[0], 0x10111213141516171810111213141516, "append_usize_value_1"); - assert_eq!(*bytes.data[1], 0x17180101020102030400000001000000, "append_usize_value_2"); - bytes = BytesTrait::new(bytes.size(), bytes.data); + assert_eq!(*bytes[0], 0x10111213141516171810111213141516, "append_usize_value_1"); + assert_eq!(*bytes[1], 0x17180101020102030400000001000000, "append_usize_value_2"); + bytes = BytesTrait::new(bytes.size(), bytes.data()); // append_u64 bytes.append_u64(0x030405060708); assert_eq!(bytes.size(), 37, "append_u64_size"); - assert_eq!(*bytes.data[0], 0x10111213141516171810111213141516, "append_u64_value_1"); - assert_eq!(*bytes.data[1], 0x17180101020102030400000001000003, "append_u64_value_2"); - assert_eq!(*bytes.data[2], 0x04050607080000000000000000000000, "append_u64_value_3"); - bytes = BytesTrait::new(bytes.size(), bytes.data); + assert_eq!(*bytes[0], 0x10111213141516171810111213141516, "append_u64_value_1"); + assert_eq!(*bytes[1], 0x17180101020102030400000001000003, "append_u64_value_2"); + assert_eq!(*bytes[2], 0x04050607080000000000000000000000, "append_u64_value_3"); + bytes = BytesTrait::new(bytes.size(), bytes.data()); // append_u128 bytes.append_u128(0x101112131415161718); assert_eq!(bytes.size(), 53, "append_u128_size"); - assert_eq!(*bytes.data[0], 0x10111213141516171810111213141516, "append_u128_value_1"); - assert_eq!(*bytes.data[1], 0x17180101020102030400000001000003, "append_u128_value_2"); - assert_eq!(*bytes.data[2], 0x04050607080000000000000010111213, "append_u128_value_3"); - assert_eq!(*bytes.data[3], 0x14151617180000000000000000000000, "append_u128_value_4"); - bytes = BytesTrait::new(bytes.size(), bytes.data); + assert_eq!(*bytes[0], 0x10111213141516171810111213141516, "append_u128_value_1"); + assert_eq!(*bytes[1], 0x17180101020102030400000001000003, "append_u128_value_2"); + assert_eq!(*bytes[2], 0x04050607080000000000000010111213, "append_u128_value_3"); + assert_eq!(*bytes[3], 0x14151617180000000000000000000000, "append_u128_value_4"); + bytes = BytesTrait::new(bytes.size(), bytes.data()); // append_u256 bytes.append_u256(u256 { low: 0x01020304050607, high: 0x010203040506070809 }); assert_eq!(bytes.size(), 85, "append_u256_size"); - assert_eq!(*bytes.data[0], 0x10111213141516171810111213141516, "append_u256_value_1"); - assert_eq!(*bytes.data[1], 0x17180101020102030400000001000003, "append_u256_value_2"); - assert_eq!(*bytes.data[2], 0x04050607080000000000000010111213, "append_u256_value_3"); - assert_eq!(*bytes.data[3], 0x14151617180000000000000001020304, "append_u256_value_4"); - assert_eq!(*bytes.data[4], 0x05060708090000000000000000000102, "append_u256_value_5"); - assert_eq!(*bytes.data[5], 0x03040506070000000000000000000000, "append_u256_value_6"); - bytes = BytesTrait::new(bytes.size(), bytes.data); + assert_eq!(*bytes[0], 0x10111213141516171810111213141516, "append_u256_value_1"); + assert_eq!(*bytes[1], 0x17180101020102030400000001000003, "append_u256_value_2"); + assert_eq!(*bytes[2], 0x04050607080000000000000010111213, "append_u256_value_3"); + assert_eq!(*bytes[3], 0x14151617180000000000000001020304, "append_u256_value_4"); + assert_eq!(*bytes[4], 0x05060708090000000000000000000102, "append_u256_value_5"); + assert_eq!(*bytes[5], 0x03040506070000000000000000000000, "append_u256_value_6"); + bytes = BytesTrait::new(bytes.size(), bytes.data()); // append_address let address = 0x015401855d7796176b05d160196ff92381eb7910f5446c2e0e04e13db2194a4f @@ -526,14 +526,14 @@ fn test_bytes_append() { .unwrap(); bytes.append_address(address); assert_eq!(bytes.size(), 117, "append_address_size"); - assert_eq!(*bytes.data[0], 0x10111213141516171810111213141516, "append_address_value_1"); - assert_eq!(*bytes.data[1], 0x17180101020102030400000001000003, "append_address_value_2"); - assert_eq!(*bytes.data[2], 0x04050607080000000000000010111213, "append_address_value_3"); - assert_eq!(*bytes.data[3], 0x14151617180000000000000001020304, "append_address_value_4"); - assert_eq!(*bytes.data[4], 0x05060708090000000000000000000102, "append_address_value_5"); - assert_eq!(*bytes.data[5], 0x0304050607015401855d7796176b05d1, "append_address_value_6"); - assert_eq!(*bytes.data[6], 0x60196ff92381eb7910f5446c2e0e04e1, "append_address_value_7"); - assert_eq!(*bytes.data[7], 0x3db2194a4f0000000000000000000000, "append_address_value_8"); + assert_eq!(*bytes[0], 0x10111213141516171810111213141516, "append_address_value_1"); + assert_eq!(*bytes[1], 0x17180101020102030400000001000003, "append_address_value_2"); + assert_eq!(*bytes[2], 0x04050607080000000000000010111213, "append_address_value_3"); + assert_eq!(*bytes[3], 0x14151617180000000000000001020304, "append_address_value_4"); + assert_eq!(*bytes[4], 0x05060708090000000000000000000102, "append_address_value_5"); + assert_eq!(*bytes[5], 0x0304050607015401855d7796176b05d1, "append_address_value_6"); + assert_eq!(*bytes[6], 0x60196ff92381eb7910f5446c2e0e04e1, "append_address_value_7"); + assert_eq!(*bytes[7], 0x3db2194a4f0000000000000000000000, "append_address_value_8"); } #[test] @@ -560,52 +560,52 @@ fn test_bytes_concat() { bytes.concat(@other); assert_eq!(bytes.size(), 163, "concat_size"); - assert_eq!(*bytes.data[0], 0x10111213141516171810111213141516, "concat_value_1"); - assert_eq!(*bytes.data[1], 0x17180101020102030400000001000003, "concat_value_2"); - assert_eq!(*bytes.data[2], 0x04050607080000000000000010111213, "concat_value_3"); - assert_eq!(*bytes.data[3], 0x14151617180000000000000001020304, "concat_value_4"); - assert_eq!(*bytes.data[4], 0x05060708090000000000000000000102, "concat_value_5"); - assert_eq!(*bytes.data[5], 0x0304050607015401855d7796176b05d1, "concat_value_6"); - assert_eq!(*bytes.data[6], 0x60196ff92381eb7910f5446c2e0e04e1, "concat_value_7"); - assert_eq!(*bytes.data[7], 0x3db2194a4f0102030405060708091011, "concat_value_8"); - assert_eq!(*bytes.data[8], 0x121314015401855d7796176b05d16019, "concat_value_9"); - assert_eq!(*bytes.data[9], 0x6ff92381eb7910f5446c2e0e04e13db2, "concat_value_10"); - assert_eq!(*bytes.data[10], 0x194a4f00000000000000000000000000, "concat_value_11"); - bytes = BytesTrait::new(bytes.size(), bytes.data); + assert_eq!(*bytes[0], 0x10111213141516171810111213141516, "concat_value_1"); + assert_eq!(*bytes[1], 0x17180101020102030400000001000003, "concat_value_2"); + assert_eq!(*bytes[2], 0x04050607080000000000000010111213, "concat_value_3"); + assert_eq!(*bytes[3], 0x14151617180000000000000001020304, "concat_value_4"); + assert_eq!(*bytes[4], 0x05060708090000000000000000000102, "concat_value_5"); + assert_eq!(*bytes[5], 0x0304050607015401855d7796176b05d1, "concat_value_6"); + assert_eq!(*bytes[6], 0x60196ff92381eb7910f5446c2e0e04e1, "concat_value_7"); + assert_eq!(*bytes[7], 0x3db2194a4f0102030405060708091011, "concat_value_8"); + assert_eq!(*bytes[8], 0x121314015401855d7796176b05d16019, "concat_value_9"); + assert_eq!(*bytes[9], 0x6ff92381eb7910f5446c2e0e04e13db2, "concat_value_10"); + assert_eq!(*bytes[10], 0x194a4f00000000000000000000000000, "concat_value_11"); + bytes = BytesTrait::new(bytes.size(), bytes.data()); // empty bytes concat let mut empty_bytes = BytesTrait::new_empty(); empty_bytes.concat(@bytes); assert_eq!(bytes.size(), 163, "concat_size"); - assert_eq!(*bytes.data[0], 0x10111213141516171810111213141516, "concat_value_1"); - assert_eq!(*bytes.data[1], 0x17180101020102030400000001000003, "concat_value_2"); - assert_eq!(*bytes.data[2], 0x04050607080000000000000010111213, "concat_value_3"); - assert_eq!(*bytes.data[3], 0x14151617180000000000000001020304, "concat_value_4"); - assert_eq!(*bytes.data[4], 0x05060708090000000000000000000102, "concat_value_5"); - assert_eq!(*bytes.data[5], 0x0304050607015401855d7796176b05d1, "concat_value_6"); - assert_eq!(*bytes.data[6], 0x60196ff92381eb7910f5446c2e0e04e1, "concat_value_7"); - assert_eq!(*bytes.data[7], 0x3db2194a4f0102030405060708091011, "concat_value_8"); - assert_eq!(*bytes.data[8], 0x121314015401855d7796176b05d16019, "concat_value_9"); - assert_eq!(*bytes.data[9], 0x6ff92381eb7910f5446c2e0e04e13db2, "concat_value_10"); - assert_eq!(*bytes.data[10], 0x194a4f00000000000000000000000000, "concat_value_11"); + assert_eq!(*bytes[0], 0x10111213141516171810111213141516, "concat_value_1"); + assert_eq!(*bytes[1], 0x17180101020102030400000001000003, "concat_value_2"); + assert_eq!(*bytes[2], 0x04050607080000000000000010111213, "concat_value_3"); + assert_eq!(*bytes[3], 0x14151617180000000000000001020304, "concat_value_4"); + assert_eq!(*bytes[4], 0x05060708090000000000000000000102, "concat_value_5"); + assert_eq!(*bytes[5], 0x0304050607015401855d7796176b05d1, "concat_value_6"); + assert_eq!(*bytes[6], 0x60196ff92381eb7910f5446c2e0e04e1, "concat_value_7"); + assert_eq!(*bytes[7], 0x3db2194a4f0102030405060708091011, "concat_value_8"); + assert_eq!(*bytes[8], 0x121314015401855d7796176b05d16019, "concat_value_9"); + assert_eq!(*bytes[9], 0x6ff92381eb7910f5446c2e0e04e13db2, "concat_value_10"); + assert_eq!(*bytes[10], 0x194a4f00000000000000000000000000, "concat_value_11"); // concat empty_bytes let empty_bytes = BytesTrait::new_empty(); bytes.concat(@empty_bytes); assert_eq!(bytes.size(), 163, "concat_size"); - assert_eq!(*bytes.data[0], 0x10111213141516171810111213141516, "concat_value_1"); - assert_eq!(*bytes.data[1], 0x17180101020102030400000001000003, "concat_value_2"); - assert_eq!(*bytes.data[2], 0x04050607080000000000000010111213, "concat_value_3"); - assert_eq!(*bytes.data[3], 0x14151617180000000000000001020304, "concat_value_4"); - assert_eq!(*bytes.data[4], 0x05060708090000000000000000000102, "concat_value_5"); - assert_eq!(*bytes.data[5], 0x0304050607015401855d7796176b05d1, "concat_value_6"); - assert_eq!(*bytes.data[6], 0x60196ff92381eb7910f5446c2e0e04e1, "concat_value_7"); - assert_eq!(*bytes.data[7], 0x3db2194a4f0102030405060708091011, "concat_value_8"); - assert_eq!(*bytes.data[8], 0x121314015401855d7796176b05d16019, "concat_value_9"); - assert_eq!(*bytes.data[9], 0x6ff92381eb7910f5446c2e0e04e13db2, "concat_value_10"); - assert_eq!(*bytes.data[10], 0x194a4f00000000000000000000000000, "concat_value_11"); + assert_eq!(*bytes[0], 0x10111213141516171810111213141516, "concat_value_1"); + assert_eq!(*bytes[1], 0x17180101020102030400000001000003, "concat_value_2"); + assert_eq!(*bytes[2], 0x04050607080000000000000010111213, "concat_value_3"); + assert_eq!(*bytes[3], 0x14151617180000000000000001020304, "concat_value_4"); + assert_eq!(*bytes[4], 0x05060708090000000000000000000102, "concat_value_5"); + assert_eq!(*bytes[5], 0x0304050607015401855d7796176b05d1, "concat_value_6"); + assert_eq!(*bytes[6], 0x60196ff92381eb7910f5446c2e0e04e1, "concat_value_7"); + assert_eq!(*bytes[7], 0x3db2194a4f0102030405060708091011, "concat_value_8"); + assert_eq!(*bytes[8], 0x121314015401855d7796176b05d16019, "concat_value_9"); + assert_eq!(*bytes[9], 0x6ff92381eb7910f5446c2e0e04e13db2, "concat_value_10"); + assert_eq!(*bytes[10], 0x194a4f00000000000000000000000000, "concat_value_11"); } #[test] diff --git a/src/encoding/src/sol_abi/encode_as.cairo b/src/encoding/src/sol_abi/encode_as.cairo index a6220e64..8109105d 100644 --- a/src/encoding/src/sol_abi/encode_as.cairo +++ b/src/encoding/src/sol_abi/encode_as.cairo @@ -63,7 +63,7 @@ pub impl SolAbiEncodeAsBytes31 of SolAbiEncodeAsTrait { pub impl SolAbiEncodeAsBytes of SolAbiEncodeAsTrait { fn encode_as(mut self: Bytes, byteSize: usize, x: Bytes) -> Bytes { - self.concat(@BytesTrait::new(byteSize, x.data)); + self.concat(@BytesTrait::new(byteSize, x.data())); self } } @@ -71,7 +71,7 @@ pub impl SolAbiEncodeAsBytes of SolAbiEncodeAsTrait { pub impl SolAbiEncodeAsByteArray of SolAbiEncodeAsTrait { fn encode_as(mut self: Bytes, byteSize: usize, x: ByteArray) -> Bytes { let x: Bytes = x.into(); - self.concat(@BytesTrait::new(byteSize, x.data)); + self.concat(@BytesTrait::new(byteSize, x.data())); self } } diff --git a/src/encoding/src/tests/sol_abi.cairo b/src/encoding/src/tests/sol_abi.cairo index 9db7823a..39354a5f 100644 --- a/src/encoding/src/tests/sol_abi.cairo +++ b/src/encoding/src/tests/sol_abi.cairo @@ -13,9 +13,6 @@ fn compare_bytes(actual: @Bytes, expected: @Bytes) -> bool { if actual.size() != expected.size() { return false; } - if actual.data.len() != expected.data.len() { - return false; - } let mut i: usize = 0; while i < actual .size() {