Skip to content

Commit

Permalink
Merge branch 'main' into fix/remove-unused-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonTulp authored Dec 4, 2024
2 parents 5318eaa + 5bcef28 commit 41ded09
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

45 changes: 31 additions & 14 deletions pallet/xrpl-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use xrpl_codec::{
traits::BinarySerialize,
transaction::{
NFTokenAcceptOffer, NFTokenCreateOffer, Payment, PaymentAltCurrency,
PaymentWithDestinationTag, SignerListSet,
PaymentAltCurrencyWithDestinationTag, PaymentWithDestinationTag, SignerListSet,
},
types::{AccountIdType, AmountType, IssuedAmountType, IssuedValueType},
};
Expand Down Expand Up @@ -1555,7 +1555,7 @@ impl<T: Config> Pallet<T> {
fn serialize_asset_tx(
tx_data: AssetWithdrawTransaction,
door_address: [u8; 20],
_destination_tag: Option<u32>,
destination_tag: Option<u32>,
) -> Result<Vec<u8>, DispatchError> {
let AssetWithdrawTransaction {
tx_fee,
Expand All @@ -1579,18 +1579,35 @@ impl<T: Config> Pallet<T> {
IssuedAmountType::from_issued_value(value_type, currency.into(), issuer)
.map_err(|_| Error::<T>::InvalidCurrencyCode)?;
let amount: Amount = Amount(AmountType::Issued(issued_amount));
let payment = PaymentAltCurrency::new(
door_address,
destination.into(),
amount,
tx_nonce,
tx_ticket_sequence,
tx_fee,
SourceTag::<T>::get(),
// omit signer key since this is a 'MultiSigner' tx
None,
);
Ok(payment.binary_serialize(true))
let tx_blob = if let Some(destination_tag) = destination_tag {
PaymentAltCurrencyWithDestinationTag::new(
door_address,
destination.into(),
amount,
tx_nonce,
tx_ticket_sequence,
tx_fee,
SourceTag::<T>::get(),
destination_tag,
// omit signer key since this is a 'MultiSigner' tx
None,
)
.binary_serialize(true)
} else {
PaymentAltCurrency::new(
door_address,
destination.into(),
amount,
tx_nonce,
tx_ticket_sequence,
tx_fee,
SourceTag::<T>::get(),
// omit signer key since this is a 'MultiSigner' tx
None,
)
.binary_serialize(true)
};
Ok(tx_blob)
}

/// Saturate the balance so that we don't lose precision when we later convert it to
Expand Down
68 changes: 68 additions & 0 deletions pallet/xrpl-bridge/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3457,6 +3457,74 @@ mod withdraw_asset {
})
}

#[test]
fn withdraw_asset_with_destination_tag_works() {
const TEST_ASSET_ID: u32 = 5;
let initial_balance = 2000;
TestExt::<Test>::default()
.with_asset(TEST_ASSET_ID, "TEST", &[(alice(), initial_balance)])
.build()
.execute_with(|| {
// For this test we will set the door_tx_fee to 0
assert_ok!(XRPLBridge::set_door_tx_fee(
frame_system::RawOrigin::Root.into(),
XRPLDoorAccount::Main,
0_u64
));
let door = XrplAccountId::from_slice(b"5490B68F2d16B3E87cba");

// Setup the asset map
let issuer = XrplAccountId::from_slice(b"6490B68F1116BFE87DDD");
let currency = XRPLCurrencyType::NonStandard(
hex!("524F4F5400000000000000000000000000000000").into(),
);
let xrpl_currency = XRPLCurrency { symbol: currency, issuer };
assert_ok!(XRPLBridge::set_xrpl_asset_map(
RuntimeOrigin::root(),
TEST_ASSET_ID,
Some(xrpl_currency)
));

// set initial ticket sequence params
assert_ok!(XRPLBridge::set_ticket_sequence_current_allocation(
RuntimeOrigin::root(),
XRPLDoorAccount::Main,
1_u32,
1_u32,
200_u32
));
assert_ok!(XRPLBridge::set_door_address(
RuntimeOrigin::root(),
XRPLDoorAccount::Main,
Some(door)
));

// Withdraw full amount
let destination = XrplAccountId::from_slice(b"6490B68F1116BFE87DDD");
let destination_tag = 1234;
assert_ok!(XRPLBridge::withdraw(
RuntimeOrigin::signed(alice()),
TEST_ASSET_ID,
initial_balance,
destination,
Some(destination_tag)
));
assert_eq!(AssetsExt::balance(TEST_ASSET_ID, &alice()), 0);

// Ensure event is thrown
System::assert_last_event(
Event::<Test>::WithdrawRequest {
proof_id: 0,
sender: alice(),
asset_id: TEST_ASSET_ID,
amount: initial_balance,
destination: destination.clone(),
}
.into(),
);
})
}

#[test]
fn withdraw_asset_no_asset_map_fails() {
const TEST_ASSET_ID: u32 = 5;
Expand Down

0 comments on commit 41ded09

Please sign in to comment.