Skip to content

Conversation

@swimricky
Copy link
Contributor

Add new unit test for reading with cursor, update test setup

Addresses feedback from #779

Add new unit test for reading with cursor, update test setup
@swimricky swimricky requested a review from jayantk April 26, 2023 15:30
@vercel
Copy link

vercel bot commented Apr 26, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
example-oracle-amm ⬜️ Ignored (Inspect) Apr 26, 2023 9:16pm
xc-admin-frontend ⬜️ Ignored (Inspect) Apr 26, 2023 9:16pm

if target_size_delta > 0 {
// allow for delta == 0 in case Rent requirements have changed
// and additional lamports need to be transferred.
// the realloc step will be a no-op in this case.
Copy link
Contributor

Choose a reason for hiding this comment

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

smart

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

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

I'm going to approve this but we should definitely decide on the endianness issue



let mut cursor = std::io::Cursor::new(&account_info_data[10..]);
let header_len = cursor.read_u16::<LittleEndian>().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

i think we agreed that everything would be big endian. it's going to be very confusing if this is little endian while everything else is big endian.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The MessageBuffer fields are only ever going to be read by the Pythnet validator & Hermes. I'm not sure off the top of my head how to combine BigEndian with zero_copy but i'll leave that as something to look into later on

let end_offset = header_len + header_end;
let accumulator_input_data =
&account_info_data[header_begin as usize..end_offset as usize];
header_end = cursor.read_u16::<LittleEndian>().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

header_end and header_begin are bad names for these two variables because they move to other locations in this loop

let discriminator = &mut sighash("accounts", "MessageBuffer");
let destination = &mut vec![0u8; 10_240 - header_len];


Copy link
Contributor

Choose a reason for hiding this comment

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

you've copy/pasted a lot of code to initialize message buffers in these tests. I recommend extracting out a helper method that sets everything up for you.

Copy link
Contributor

Choose a reason for hiding this comment

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

actually these tests seem to have lots of repeated code blocks in them. I think this isn't ideal -- you should think about how to factor things into helper methods to reduce duplication.

@swimricky swimricky merged commit 04576df into main Apr 26, 2023
@swimricky swimricky deleted the message-buffer/779_feedback branch April 26, 2023 21:16
@swimricky swimricky changed the title fix(message-buffer): address PR feedback from 779, update tests [message-buffer 11/x] - fix(message-buffer): address PR feedback from 779, update tests May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants