Skip to content

Commit

Permalink
add more tests, update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed Jan 28, 2025
1 parent cca33cc commit 6b72985
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 26 deletions.
1 change: 1 addition & 0 deletions crates/astria-sequencer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Use bridge address to determine asset in bridge unlock cost estimation instead
of signer [#1905](https://github.com/astriaorg/astria/pull/1905).
- Add more thorough unit tests for all actions [#1916](https://github.com/astriaorg/astria/pull/1916).
- Implement `BridgeTransfer` action [#1934](https://github.com/astriaorg/astria/pull/1934).

## [1.0.0] - 2024-10-25

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl ActionHandler for BridgeTransfer {
mod test {
use astria_core::{
primitive::v1::{
asset::Denom,
RollupId,
TransactionId,
},
Expand All @@ -119,6 +120,7 @@ mod test {
address::StateWriteExt as _,
assets::StateWriteExt as _,
benchmark_and_test_utils::{
assert_eyre_error,
astria_address,
ASTRIA_PREFIX,
},
Expand Down Expand Up @@ -178,6 +180,71 @@ mod test {
};

bridge_unlock.check_stateless().await.unwrap();
bridge_unlock.check_and_execute(state).await.unwrap();
bridge_unlock.check_and_execute(&mut state).await.unwrap();

let deposits = state
.get_cached_block_deposits()
.values()
.next()
.unwrap()
.clone();
assert_eq!(deposits.len(), 1);
}

#[tokio::test]
async fn bridge_transfer_accounts_have_different_asset_fails() {
let storage = cnidarium::TempStorage::new().await.unwrap();
let snapshot = storage.latest_snapshot();
let mut state = StateDelta::new(snapshot);

let from_address = astria_address(&[1; 20]);
state.put_transaction_context(TransactionContext {
address_bytes: *from_address.address_bytes(),
transaction_id: TransactionId::new([0; 32]),
position_in_transaction: 0,
});
state.put_base_prefix(ASTRIA_PREFIX.to_string()).unwrap();

let asset = test_asset();
let transfer_amount = 100;

let to_address = astria_address(&[2; 20]);
state
.put_bridge_account_ibc_asset(&from_address, &asset)
.unwrap();
state
.put_bridge_account_withdrawer_address(&from_address, from_address)
.unwrap();
state
.put_bridge_account_ibc_asset(&to_address, &"other-asset".parse::<Denom>().unwrap())
.unwrap();
let to_rollup_id = RollupId::new([3; 32]);
state
.put_bridge_account_rollup_id(&to_address, to_rollup_id)
.unwrap();
state
.put_ibc_asset(test_asset().unwrap_trace_prefixed().clone())
.unwrap();
state
.put_account_balance(&from_address, &asset, transfer_amount)
.unwrap();

let bridge_unlock = BridgeTransfer {
to: to_address,
amount: transfer_amount,
fee_asset: asset.clone(),
memo: String::new(),
bridge_address: from_address,
rollup_block_number: 1,
rollup_withdrawal_event_id: "a-rollup-defined-hash".to_string(),
destination_chain_address: "noot".to_string(),
};

bridge_unlock.check_stateless().await.unwrap();
let result = bridge_unlock.check_and_execute(state).await;
assert_eyre_error(
&result.unwrap_err(),
"bridge accounts must have the same asset",
);
}
}
50 changes: 25 additions & 25 deletions proto/protocolapis/astria/protocol/transaction/v1/action.proto
Original file line number Diff line number Diff line change
Expand Up @@ -213,32 +213,32 @@ message BridgeSudoChange {
}

message BridgeTransfer {
// the address of the bridge account to transfer to
astria.primitive.v1.Address to = 1;
// the amount to transfer
astria.primitive.v1.Uint128 amount = 2;
// the asset used to pay the transaction fee
string fee_asset = 3;
// the address on the destination chain which
// will receive the bridged funds
string destination_chain_address = 4;
// the address of the bridge account to transfer to
astria.primitive.v1.Address to = 1;
// the amount to transfer
astria.primitive.v1.Uint128 amount = 2;
// the asset used to pay the transaction fee
string fee_asset = 3;
// the address on the destination chain which
// will receive the bridged funds
string destination_chain_address = 4;

// The memo field can be used to provide unique identifying additional
// information about the bridge unlock transaction.
string memo = 5;
// the address of the bridge account to transfer from
astria.primitive.v1.Address bridge_address = 6;
// The block number on the rollup that triggered the transaction underlying
// this bridge unlock memo.
uint64 rollup_block_number = 7;
// An identifier of the original rollup event, such as a transaction hash which
// triggered a bridge unlock and is underlying event that led to this bridge
// unlock. This can be utilized for tracing from the bridge back to
// distinct rollup events.
//
// This field is of type `string` so that it can be formatted in the preferred
// format of the rollup when targeting plain text encoding.
string rollup_withdrawal_event_id = 8;
// The memo field can be used to provide unique identifying additional
// information about the bridge unlock transaction.
string memo = 5;
// the address of the bridge account to transfer from
astria.primitive.v1.Address bridge_address = 6;
// The block number on the rollup that triggered the transaction underlying
// this bridge unlock memo.
uint64 rollup_block_number = 7;
// An identifier of the original rollup event, such as a transaction hash which
// triggered a bridge unlock and is underlying event that led to this bridge
// unlock. This can be utilized for tracing from the bridge back to
// distinct rollup events.
//
// This field is of type `string` so that it can be formatted in the preferred
// format of the rollup when targeting plain text encoding.
string rollup_withdrawal_event_id = 8;
}

message FeeChange {
Expand Down

0 comments on commit 6b72985

Please sign in to comment.