Skip to content

Commit

Permalink
fix test (#17310)
Browse files Browse the repository at this point in the history
(cherry picked from commit cfcae50)

# Conflicts:
#	programs/bpf/c/src/ser/ser.c
  • Loading branch information
jackcmay authored and mergify-bot committed May 18, 2021
1 parent d2e9076 commit 56c4d0f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions programs/bpf/c/src/ser/ser.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @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[2];
SolParameters params = (SolParameters){.ka = ka};

sol_log(__FILE__);

if (!sol_deserialize(input, &params, SOL_ARRAY_SIZE(ka))) {
return ERROR_INVALID_ARGUMENT;
}

char ka_data[] = {1, 2, 3};
SolPubkey ka_owner;
sol_memset(ka_owner.x, 0, SIZE_PUBKEY); // set to system program

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;
}

0 comments on commit 56c4d0f

Please sign in to comment.