forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add C Serialization Tests for solana-labs#17217
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @brief Example C-based BPF sanity rogram that prints out the parameters | ||
* passed to it | ||
*/ | ||
#include <solana_sdk.h> | ||
|
||
extern uint64_t entrypoint(const uint8_t *input) { | ||
SolAccountInfo ka[1]; | ||
SolParameters params = (SolParameters){.ka = ka}; | ||
|
||
sol_log(__FILE__); | ||
|
||
if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) { | ||
return ERROR_INVALID_ARGUMENT; | ||
} | ||
|
||
char ka_data[] = {1, 2, 3}; | ||
SolPubkey ka_owner; | ||
sol_assert(params.ka_num == 2); | ||
for (int i = 0; i < 2; i++) { | ||
sol_assert(*params.ka[i].lamports == 42); | ||
sol_assert(!sol_memcmp(params.ka[i].data, ka_data, 4)); | ||
sol_assert(SolPubkey_same(params.ka[i].owner, &ka_owner)); | ||
sol_assert(params.ka[i].is_signer == false); | ||
sol_assert(params.ka[i].is_writable == false); | ||
sol_assert(params.ka[i].executable == false); | ||
} | ||
|
||
char data[] = {4, 5, 6, 7}; | ||
sol_assert(params.data_len = 4); | ||
sol_assert(!sol_memcmp(params.data, data, 4)); | ||
|
||
return SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters