From bea78fc8973a45817d7b0af93db4562dc8ac6951 Mon Sep 17 00:00:00 2001 From: De Facto Date: Thu, 4 Feb 2021 16:17:08 +0800 Subject: [PATCH] cargo fmt --- program/src/error.rs | 15 ++++++----- program/src/processor.rs | 57 +++++++++++++++++++++++++++++----------- program/src/state.rs | 6 ++--- 3 files changed, 52 insertions(+), 26 deletions(-) diff --git a/program/src/error.rs b/program/src/error.rs index dd77781..bbb1a0d 100644 --- a/program/src/error.rs +++ b/program/src/error.rs @@ -1,7 +1,12 @@ //! Error types use num_derive::FromPrimitive; -use solana_program::{decode_error::DecodeError, entrypoint::ProgramResult, msg, program_error::{PrintProgramError, ProgramError}}; +use solana_program::{ + decode_error::DecodeError, + entrypoint::ProgramResult, + msg, + program_error::{PrintProgramError, ProgramError}, +}; use num_traits::FromPrimitive; use thiserror::Error; @@ -90,12 +95,8 @@ impl From for ProgramError { impl From for Error { fn from(err: ProgramError) -> Self { match err { - ProgramError::Custom(code) => { - Error::from_u32(code).unwrap_or(Error::UnknownError) - }, - _ => { - Error::UnknownError - } + ProgramError::Custom(code) => Error::from_u32(code).unwrap_or(Error::UnknownError), + _ => Error::UnknownError, } } } diff --git a/program/src/processor.rs b/program/src/processor.rs index ce85b2f..906cfec 100644 --- a/program/src/processor.rs +++ b/program/src/processor.rs @@ -239,7 +239,7 @@ impl<'a> SubmitContext<'a> { fn start_new_round(&self, aggregator: &mut Aggregator, oracle: &mut Oracle) -> ProgramResult { let now = self.clock.unix_timestamp as u64; - if aggregator.current_round.id < oracle.allow_start_round { + if aggregator.current_round.id < oracle.allow_start_round { return Err(Error::OracleNewRoundCooldown)?; } @@ -305,10 +305,10 @@ impl Processor { } .process(), _ => Err(ProgramError::InvalidInstructionData), - // Instruction::Withdraw { amount, seed } => { - // msg!("Instruction: Withdraw"); - // Self::process_withdraw(accounts, amount, seed) - // } + // Instruction::Withdraw { amount, seed } => { + // msg!("Instruction: Withdraw"); + // Self::process_withdraw(accounts, amount, seed) + // } } } } @@ -481,7 +481,8 @@ mod tests { let program_id = Pubkey::new_unique(); let (mut aggregator, mut aggregator_owner) = create_aggregator(&program_id)?; - let (mut oracle, mut oracle_owner) = create_oracle(&program_id, &mut aggregator, &mut aggregator_owner)?; + let (mut oracle, mut oracle_owner) = + create_oracle(&program_id, &mut aggregator, &mut aggregator_owner)?; process( &program_id, @@ -505,7 +506,14 @@ mod tests { } impl SubmitTestFixture { - fn submit(&mut self, oracle: &mut TAccount, oracle_owner: &mut TAccount, time: u64, round_id: u64, value: u64) -> Result { + fn submit( + &mut self, + oracle: &mut TAccount, + oracle_owner: &mut TAccount, + time: u64, + round_id: u64, + value: u64, + ) -> Result { let mut clock = sysclock(time as i64); process( @@ -528,9 +536,12 @@ mod tests { let program_id = Pubkey::new_unique(); let (mut aggregator, mut aggregator_owner) = create_aggregator(&program_id)?; - let (mut oracle, mut oracle_owner) = create_oracle(&program_id, &mut aggregator, &mut aggregator_owner)?; - let (mut oracle2, mut oracle_owner2) = create_oracle(&program_id, &mut aggregator, &mut aggregator_owner)?; - let (mut oracle3, mut oracle_owner3) = create_oracle(&program_id, &mut aggregator, &mut aggregator_owner)?; + let (mut oracle, mut oracle_owner) = + create_oracle(&program_id, &mut aggregator, &mut aggregator_owner)?; + let (mut oracle2, mut oracle_owner2) = + create_oracle(&program_id, &mut aggregator, &mut aggregator_owner)?; + let (mut oracle3, mut oracle_owner3) = + create_oracle(&program_id, &mut aggregator, &mut aggregator_owner)?; let mut fixture = SubmitTestFixture { program_id, @@ -551,7 +562,9 @@ mod tests { // test: should fail with repeated submission assert_eq!( - fixture.submit(&mut oracle, &mut oracle_owner, time+10, 0, 2).map_err(Error::from), + fixture + .submit(&mut oracle, &mut oracle_owner, time + 10, 0, 2) + .map_err(Error::from), Err(Error::OracleAlreadySubmitted), "should fail if oracle submits repeatedly in the same round" ); @@ -576,7 +589,9 @@ mod tests { // test: max submission reached assert_eq!( - fixture.submit(&mut oracle3, &mut oracle_owner3, time+10, 0, 2).map_err(Error::from), + fixture + .submit(&mut oracle3, &mut oracle_owner3, time + 10, 0, 2) + .map_err(Error::from), Err(Error::MaxSubmissionsReached), ); @@ -592,7 +607,11 @@ mod tests { assert_eq!(sub.oracle, oracle.pubkey.to_bytes()); assert_eq!(sub.value, 10); assert_eq!(sub.updated_at, time); - assert_eq!(round.submissions[1].is_initialized(), false, "other submissions should've been zero after starting a new round"); + assert_eq!( + round.submissions[1].is_initialized(), + false, + "other submissions should've been zero after starting a new round" + ); // the last round answer should be reserved let answer = &agr.answer; @@ -603,7 +622,9 @@ mod tests { // test: oracle cannot immediately start a new round assert_eq!( - fixture.submit(&mut oracle, &mut oracle_owner, time+10, 2, 2).map_err(Error::from), + fixture + .submit(&mut oracle, &mut oracle_owner, time + 10, 2, 2) + .map_err(Error::from), Err(Error::OracleNewRoundCooldown), ); @@ -640,13 +661,17 @@ mod tests { // InvalidRoundID assert_eq!( - fixture.submit(&mut oracle, &mut oracle_owner, time+10, 10, 1000).map_err(Error::from), + fixture + .submit(&mut oracle, &mut oracle_owner, time + 10, 10, 1000) + .map_err(Error::from), Err(Error::InvalidRoundID), "should only be able to start a round with current_round.id + 1" ); assert_eq!( - fixture.submit(&mut oracle3, &mut oracle_owner3, time+10, 3, 1000).map_err(Error::from), + fixture + .submit(&mut oracle3, &mut oracle_owner3, time + 10, 3, 1000) + .map_err(Error::from), Err(Error::InvalidRoundID), "should not be able to submit answer to previous rounds" ); diff --git a/program/src/state.rs b/program/src/state.rs index 2a5270e..2cf4ee4 100644 --- a/program/src/state.rs +++ b/program/src/state.rs @@ -43,9 +43,9 @@ pub struct Answer { } impl IsInitialized for Answer { - fn is_initialized(&self) -> bool { - self.created_at > 0 - } + fn is_initialized(&self) -> bool { + self.created_at > 0 + } } /// Aggregator data.