Skip to content

Commit 97767df

Browse files
committed
Update commit test
1 parent a6571c6 commit 97767df

3 files changed

Lines changed: 44 additions & 43 deletions

File tree

‎src/processor/fast/commit_state.rs‎

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use borsh::BorshDeserialize;
2-
use pinocchio::instruction::{Seed, Signer};
2+
use pinocchio::instruction::Signer;
33
use pinocchio::pubkey::{self, pubkey_eq};
44
use pinocchio::seeds;
55
use pinocchio::{
@@ -28,7 +28,7 @@ pub fn process_commit_state(
2828
accounts: &[AccountInfo],
2929
data: &[u8],
3030
) -> ProgramResult {
31-
let args = CommitStateArgs::try_from_slice(data).expect("FIXME");
31+
let args = CommitStateArgs::try_from_slice(data).map_err(|_| ProgramError::BorshIoError)?;
3232

3333
let commit_state_bytes: &[u8] = args.data.as_ref();
3434
let commit_record_lamports = args.lamports;
@@ -109,20 +109,18 @@ pub(crate) fn process_commit_state_internal(
109109

110110
// To preserve correct history of account updates we require sequential commits
111111
if args.commit_record_nonce != delegation_metadata.last_update_nonce + 1 {
112-
//msg!(
113-
// "Nonce {} is incorrect, previous nonce is {}. Rejecting commit",
114-
// args.commit_record_nonce,
115-
// delegation_metadata.last_update_nonce
116-
//);
112+
log!(
113+
"Nonce {} is incorrect, previous nonce is {}. Rejecting commit",
114+
args.commit_record_nonce,
115+
delegation_metadata.last_update_nonce
116+
);
117117
return Err(DlpError::NonceOutOfOrder.into());
118118
}
119119

120120
// Once the account is marked as undelegatable, any subsequent commit should fail
121121
if delegation_metadata.is_undelegatable {
122-
//msg!(
123-
// "delegation metadata ({}) is already undelegated",
124-
// args.delegation_metadata_account.key
125-
//);
122+
log!("delegation metadata is already undelegated: ");
123+
pubkey::log(args.delegation_metadata_account.key());
126124
return Err(DlpError::AlreadyUndelegated.into());
127125
}
128126

@@ -139,25 +137,21 @@ pub(crate) fn process_commit_state_internal(
139137
.map_err(to_pinocchio_program_error)?;
140138

141139
// Check that the authority is allowed to commit
142-
if !pubkey_eq(
143-
&delegation_record.authority.as_array(),
144-
args.validator.key(),
145-
) && !pubkey_eq(delegation_record.authority.as_array(), &Pubkey::default())
140+
if !pubkey_eq(delegation_record.authority.as_array(), args.validator.key())
141+
&& !pubkey_eq(delegation_record.authority.as_array(), &Pubkey::default())
146142
{
147-
//msg!(
148-
// "validator ({}) is not the delegation authority ({})",
149-
// args.validator.key,
150-
// delegation_record.authority
151-
//);
143+
log!("validator is not the delegation authority. validator: ");
144+
pubkey::log(args.validator.key());
145+
log!("delegation authority: ");
146+
pubkey::log(delegation_record.authority.as_array());
152147
return Err(DlpError::InvalidAuthority.into());
153148
}
154149

155150
// If there was an issue with the lamport accounting in the past, abort (this should never happen)
156151
if args.delegated_account.lamports() < delegation_record.lamports {
157-
//msg!(
158-
// "delegated account ({}) has less lamports than the delegation record indicates",
159-
// args.delegated_account.key
160-
//);
152+
log!(
153+
"delegated account has less lamports than the delegation record indicates. delegation account: ");
154+
pubkey::log(args.delegated_account.key());
161155
return Err(DlpError::InvalidDelegatedState.into());
162156
}
163157

@@ -192,12 +186,10 @@ pub(crate) fn process_commit_state_internal(
192186
.map_err(to_pinocchio_program_error)?;
193187
if !program_config
194188
.approved_validators
195-
.contains(&args.validator.key().clone().into())
189+
.contains(&(*args.validator.key()).into())
196190
{
197-
//msg!(
198-
// "validator ({}) is not whitelisted in the program config",
199-
// args.validator.key
200-
//);
191+
log!("validator is not whitelisted in the program config: ");
192+
pubkey::log(args.validator.key());
201193
return Err(DlpError::InvalidWhitelistProgramConfig.into());
202194
}
203195
}
@@ -223,8 +215,6 @@ pub(crate) fn process_commit_state_internal(
223215
args.commit_state_account,
224216
&crate::fast::ID,
225217
args.commit_state_bytes.len(),
226-
//commit_state_seeds_from_delegated_account!(args.delegated_account.key),
227-
//commit_state_bump,
228218
&[Signer::from(&seeds!(
229219
pda::COMMIT_STATE_TAG,
230220
args.delegated_account.key(),
@@ -248,8 +238,8 @@ pub(crate) fn process_commit_state_internal(
248238

249239
// Initialize the commit record
250240
let commit_record = CommitRecord {
251-
identity: args.validator.key().clone().into(),
252-
account: args.delegated_account.key().clone().into(),
241+
identity: (*args.validator.key()).into(),
242+
account: (*args.delegated_account.key()).into(),
253243
nonce: args.commit_record_nonce,
254244
lamports: args.commit_record_lamports,
255245
};

‎src/processor/fast/utils/requires.rs‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ pub fn require_initialized_pda(
159159
) -> Result<u8, ProgramError> {
160160
let pda = pubkey::find_program_address(seeds, program_id);
161161
if !pubkey_eq(info.key(), &pda.0) {
162-
log!("Invalid seeds for account: ");
162+
log!("Invalid seeds (label: {}) for account ", label);
163163
pubkey::log(info.key());
164164
return Err(ProgramError::InvalidSeeds);
165165
}
166166

167167
require_owned_pda(info, program_id, label)?;
168168

169169
if is_writable && !info.is_writable() {
170-
log!("Account is not writable: ");
170+
log!("Account needs to be writable. label: {}, account: ", label);
171171
pubkey::log(info.key());
172172
return Err(ProgramError::InvalidAccountData);
173173
}
@@ -244,14 +244,12 @@ pub fn require_program_config(
244244
program: &Pubkey,
245245
is_writable: bool,
246246
) -> Result<bool, ProgramError> {
247-
let pda = program_config_from_program_id(&program.clone().into());
247+
let pda = program_config_from_program_id(&(*program).into());
248248
if !pubkey_eq(pda.as_array(), program_config.key()) {
249-
//msg!(
250-
// "Invalid program config PDA, expected {} but got {}. program: {}",
251-
// pda,
252-
// program_config.key,
253-
// program
254-
//);
249+
log!("Invalid validator fees vault PDA, expected: ");
250+
pubkey::log(pda.as_array());
251+
log!("but got: ");
252+
pubkey::log(program_config.key());
255253
return Err(DlpError::InvalidAuthority.into());
256254
}
257255
require_pda(

‎tests/integration/tests/test-delegation.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,19 @@ describe("TestDelegation", () => {
225225
);
226226
const txId = await processInstruction(ix);
227227
console.log("Commit state signature", txId);
228+
229+
const tx = await fetchTransaction(txId);
230+
console.log(tx.meta.logMessages);
231+
232+
const consumedLog = tx.meta.logMessages.find((m) =>
233+
m.includes("DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh consumed")
234+
);
235+
236+
assert.isAtMost(
237+
parseInt(consumedLog.split(" ").at(3)),
238+
36000,
239+
"delegate instruction must consume less than 18500"
240+
);
228241
});
229242

230243
it("Finalize account state", async () => {
@@ -260,7 +273,7 @@ describe("TestDelegation", () => {
260273
console.log("Finalize signature", txId);
261274
});
262275

263-
it("Undelegate account", async () => {
276+
it.skip("Undelegate account", async () => {
264277
const ix = createUndelegateInstruction(
265278
validator,
266279
pda,

0 commit comments

Comments
 (0)