Skip to content

Commit

Permalink
update and merge protos
Browse files Browse the repository at this point in the history
  • Loading branch information
TalDerei committed Apr 19, 2024
2 parents 6c1d7b1 + 8d14c47 commit 6ee552b
Show file tree
Hide file tree
Showing 34 changed files with 1,936 additions and 95 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion crates/bin/pcli/src/command/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,9 @@ impl TxCmd {
.await?;
app.build_and_submit_transaction(plan).await?;
}
TxCmd::Position(PositionCmd::RewardClaim {}) => todo!(),
TxCmd::Position(PositionCmd::RewardClaim {}) => {
unimplemented!("deprecated, remove this")
}
TxCmd::Position(PositionCmd::Replicate(replicate_cmd)) => {
replicate_cmd.exec(app).await?;
}
Expand Down
7 changes: 7 additions & 0 deletions crates/bin/pcli/src/transaction_view_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,13 @@ impl TransactionViewExt for TransactionView {
penumbra_transaction::ActionView::Delegate(_) => ["Delegation", ""],
penumbra_transaction::ActionView::Undelegate(_) => ["Undelegation", ""],
penumbra_transaction::ActionView::UndelegateClaim(_) => ["Undelegation Claim", ""],
penumbra_transaction::ActionView::ActionDutchAuctionSchedule(_) => todo!(),
penumbra_transaction::ActionView::ActionDutchAuctionEnd(_) => {
todo!()
}
penumbra_transaction::ActionView::ActionDutchAuctionWithdraw(_) => {
todo!()
}
};

actions_table.add_row(row);
Expand Down
Binary file modified crates/cnidarium/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
1 change: 1 addition & 0 deletions crates/core/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ metrics = { workspace = true }
once_cell = { workspace = true }
parking_lot = { workspace = true }
penumbra-asset = { workspace = true, default-features = true }
penumbra-auction = { workspace = true, default-features = true }
penumbra-community-pool = { workspace = true, default-features = true }
penumbra-compact-block = { workspace = true, default-features = true }
penumbra-dex = { workspace = true, default-features = true }
Expand Down
18 changes: 9 additions & 9 deletions crates/core/app/src/action_handler/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ impl AppActionHandler for Action {
Action::CommunityPoolSpend(action) => action.check_stateless(()).await,
Action::CommunityPoolOutput(action) => action.check_stateless(()).await,
Action::CommunityPoolDeposit(action) => action.check_stateless(()).await,
Action::ActionDutchAuctionSchedule(_) => todo!(),
Action::ActionDutchAuctionEnd(_) => todo!(),
Action::ActionDutchAuctionWithdraw(_) => todo!(),
Action::ActionDutchAuctionSchedule(action) => action.check_stateless(()).await,
Action::ActionDutchAuctionEnd(action) => action.check_stateless(()).await,
Action::ActionDutchAuctionWithdraw(action) => action.check_stateless(()).await,
}
}

Expand Down Expand Up @@ -95,9 +95,9 @@ impl AppActionHandler for Action {
Action::CommunityPoolSpend(action) => action.check_historical(state).await,
Action::CommunityPoolOutput(action) => action.check_historical(state).await,
Action::CommunityPoolDeposit(action) => action.check_historical(state).await,
Action::ActionDutchAuctionSchedule(_) => todo!(),
Action::ActionDutchAuctionEnd(_) => todo!(),
Action::ActionDutchAuctionWithdraw(_) => todo!(),
Action::ActionDutchAuctionSchedule(action) => action.check_historical(state).await,
Action::ActionDutchAuctionEnd(action) => action.check_historical(state).await,
Action::ActionDutchAuctionWithdraw(action) => action.check_historical(state).await,
}
}

Expand Down Expand Up @@ -130,9 +130,9 @@ impl AppActionHandler for Action {
Action::CommunityPoolSpend(action) => action.check_and_execute(state).await,
Action::CommunityPoolOutput(action) => action.check_and_execute(state).await,
Action::CommunityPoolDeposit(action) => action.check_and_execute(state).await,
Action::ActionDutchAuctionSchedule(_) => todo!(),
Action::ActionDutchAuctionEnd(_) => todo!(),
Action::ActionDutchAuctionWithdraw(_) => todo!(),
Action::ActionDutchAuctionSchedule(action) => action.check_and_execute(state).await,
Action::ActionDutchAuctionEnd(action) => action.check_and_execute(state).await,
Action::ActionDutchAuctionWithdraw(action) => action.check_and_execute(state).await,
}
}
}
8 changes: 4 additions & 4 deletions crates/core/app/src/action_handler/actions/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ impl AppActionHandler for ProposalSubmit {
| CommunityPoolSpend(_)
| CommunityPoolOutput(_)
| Ics20Withdrawal(_)
| CommunityPoolDeposit(_) => {}
ActionDutchAuctionSchedule(_) => todo!(),
ActionDutchAuctionEnd(_) => todo!(),
ActionDutchAuctionWithdraw(_) => todo!(),
| CommunityPoolDeposit(_)
| ActionDutchAuctionSchedule(_)
| ActionDutchAuctionEnd(_)
| ActionDutchAuctionWithdraw(_) => {}
}
}
}
Expand Down
129 changes: 129 additions & 0 deletions crates/core/app/tests/app_can_deposit_into_community_pool.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
use {
self::common::BuilderExt,
anyhow::anyhow,
cnidarium::TempStorage,
penumbra_app::{genesis::AppState, server::consensus::Consensus},
penumbra_asset::asset,
penumbra_community_pool::{CommunityPoolDeposit, StateReadExt},
penumbra_keys::test_keys,
penumbra_mock_client::MockClient,
penumbra_mock_consensus::TestNode,
penumbra_num::Amount,
penumbra_proto::DomainType,
penumbra_shielded_pool::SpendPlan,
penumbra_transaction::{TransactionParameters, TransactionPlan},
rand_core::OsRng,
std::collections::BTreeMap,
tap::{Tap, TapFallible},
tracing::info,
};

mod common;

/// Exercises that the app can deposit a note into the community pool.
#[tokio::test]
async fn app_can_deposit_into_community_pool() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;

// Define our application state, and start the test node.
let mut test_node = {
let app_state = AppState::default();
let consensus = Consensus::new(storage.as_ref().clone());
TestNode::builder()
.single_validator()
.with_penumbra_auto_app_state(app_state)?
.init_chain(consensus)
.await
.tap_ok(|e| tracing::info!(hash = %e.last_app_hash_hex(), "finished init chain"))?
};

// Sync the mock client, using the test wallet's spend key, to the latest snapshot.
let client = MockClient::new(test_keys::SPEND_KEY.clone())
.with_sync_to_storage(&storage)
.await?
.tap(|c| info!(client.notes = %c.notes.len(), "mock client synced to test storage"));

// Take one of the test wallet's notes, and prepare to deposit it in the community pool.
let note = client
.notes
.values()
.cloned()
.next()
.ok_or_else(|| anyhow!("mock client had no note"))?;

// Create a community pool transaction.
let mut plan = {
let value = note.value();
let spend = SpendPlan::new(
&mut OsRng,
note.clone(),
client
.position(note.commit())
.ok_or_else(|| anyhow!("input note commitment was unknown to mock client"))?,
)
.into();
let deposit = CommunityPoolDeposit { value }.into();
TransactionPlan {
actions: vec![spend, deposit],
// Now fill out the remaining parts of the transaction needed for verification:
memo: None,
detection_data: None, // We'll set this automatically below
transaction_parameters: TransactionParameters {
chain_id: TestNode::<()>::CHAIN_ID.to_string(),
..Default::default()
},
}
};
plan.populate_detection_data(OsRng, 0);
let tx = client.witness_auth_build(&plan).await?;

// Execute the transaction, applying it to the chain state.
let pre_tx_snapshot = storage.latest_snapshot();
test_node
.block()
.with_data(vec![tx.encode_to_vec()])
.execute()
.await?;
let post_tx_snapshot = storage.latest_snapshot();

// Assert that the community pool balance looks correct for the deposited asset id, and that
// other amounts were not affected by the deposit.
{
type Balance = BTreeMap<asset::Id, Amount>;

let id = note.asset_id();
let pre_tx_balance = pre_tx_snapshot.community_pool_balance().await?;
let post_tx_balance = post_tx_snapshot.community_pool_balance().await?;

let get_balance_for_id = |balance: &Balance| balance.get(&id).copied().unwrap_or_default();
let pre_tx_amount = get_balance_for_id(&pre_tx_balance);
let post_tx_amount = get_balance_for_id(&post_tx_balance);
assert_eq!(
pre_tx_amount + note.amount(),
post_tx_amount,
"community pool balance should include the deposited note"
);

let count_other_assets_in_pool = |balance: &Balance| {
balance
.into_iter()
// Skip the amount for our note's asset id.
.filter(|(&entry_id, _)| entry_id != id)
.map(|(_, &amount)| amount)
.sum::<Amount>()
};
assert_eq!(
count_other_assets_in_pool(&pre_tx_balance),
count_other_assets_in_pool(&post_tx_balance),
"other community pool balance amounts should not have changed"
);
}

// Free our temporary storage.
Ok(())
.tap(|_| drop(test_node))
.tap(|_| drop(storage))
.tap(|_| drop(guard))
}
Loading

0 comments on commit 6ee552b

Please sign in to comment.