Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions e2e/test/XRPL.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("XRPL pallet", () => {
after(async () => await node.stop());

// NOTE: use this test to generate a valid xaman tx (msg + signature) for mock runtime tests
it.skip("debug tx message and signature", async () => {
it.skip("debug ECDSA tx message and signature", async () => {
// const user = Wallet.createRandom();
const publicKey = computePublicKey(alith.publicKey, true);
// console.log(hexToU8a(publicKey));
Expand Down Expand Up @@ -80,6 +80,51 @@ describe("XRPL pallet", () => {
console.log("signature", signature);
});

// NOTE: use this test to generate a valid xaman tx (msg + signature) for mock runtime tests
it.skip("debug ED25519 tx message and signature", async () => {
// const user = Wallet.createRandom();
// const publicKey = computePublicKey(alith.publicKey, true);
const importedAccount = AccountLib.derive.familySeed("sEdS4rAgVysUtD5Zmm9F8i8uJBGik4K");
const signerInstance = AccountLib.derive.privatekey(importedAccount.keypair.privateKey!);
const publicKey = computePublicKey(`0x${signerInstance.keypair.publicKey!}`, true);
const eoa = Web3.utils.toChecksumAddress(
// remove "ED" prefix from public key to compute EOA
// keccak hash produces 32 bytes (64 chars) - take last 20 bytes (40 chars)
// remove "0x" prefix from keccak hash output (2 chars)
// get last 20 bytes of the keccak hash output (12 bytes - 24 chars)
"0x" + keccak256(hexToU8a(`0x${publicKey.slice(4)}`)).slice(26),
);

await finalizeTx(alith, api.tx.assets.transfer(GAS_TOKEN_ID, eoa, 2_000_000));

genesisHash = "0000000000000000000000000000000000000000000000000000000000000000";
const extrinsic = api.tx.system.remark("Mischief Managed");
const hashedExtrinsicWithoutPrefix = blake256(extrinsic.toHex().slice(6)).toString();

const xamanJsonTx = {
AccountTxnID: "16969036626990000000000000000000F236FD752B5E4C84810AB3D41A3C2580",
SigningPubKey: publicKey.slice(2),
Account: deriveAddress(publicKey.slice(2)),
Memos: [
{
Memo: {
MemoType: stringToHex("extrinsic"),
// remove `0x` from extrinsic hex string
MemoData: stringToHex(`${genesisHash}:0:5:0:${hashedExtrinsicWithoutPrefix}`),
},
},
],
};

// sign xaman tx
const message = encode(xamanJsonTx);
const encodedSigningMessage = encodeForSigning(xamanJsonTx);
const signature = sign(encodedSigningMessage, signerInstance.keypair.privateKey);

console.log("message", message);
console.log("signature", signature);
});

it("can submit system remark extrinsic - using ecdsa signature", async () => {
const user = Wallet.createRandom();
const publicKey = computePublicKey(user.publicKey, true);
Expand Down Expand Up @@ -186,7 +231,7 @@ describe("XRPL pallet", () => {

await finalizeTx(alith, api.tx.assets.transfer(GAS_TOKEN_ID, eoa, 2_000_000));

const extrinsic = api.tx.system.remark("hi");
const extrinsic = api.tx.system.remark("Mischief Managed");
const hashedExtrinsicWithoutPrefix = blake256(extrinsic.toHex().slice(6)).toString();
const maxBlockNumber = +(await api.query.system.number()).toString() + 5;
const nonce = ((await api.query.system.account(eoa)).toJSON() as any)?.nonce;
Expand Down
6 changes: 3 additions & 3 deletions ethy-gadget/src/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ mod tests {
assert_validation_result!(ValidationResult::ProcessAndKeep(_), result);
assert!(gv.is_tracking_event(&event_id));

// set the finalized block number to 6. try to validate now. should fail since out of live
// set the finalized block number to 7. try to validate now. should fail since out of live
// window. i.e. WINDOW_SIZE = 5
let block_hashes = net.peer(0).push_blocks(7, false);
net.run_until_sync().await;
Expand Down Expand Up @@ -464,7 +464,7 @@ mod tests {
let result = gv.message_expired()(topic::<Block>(), witness.clone().encode().as_ref());
assert_eq!(result, false);

// set the finalized block number to 6. try to validate now. should fail since out of live
// set the finalized block number to 7. try to validate now. should fail since out of live
// window. i.e. WINDOW_SIZE = 5
let block_hashes = net.peer(0).push_blocks(7, false);
net.run_until_sync().await;
Expand Down Expand Up @@ -518,7 +518,7 @@ mod tests {
);
assert_eq!(result, true);

// set the finalized block number to 6. try to validate now. should fail since out of live
// set the finalized block number to 7. try to validate now. should fail since out of live
// window. i.e. WINDOW_SIZE = 5
let block_hashes = net.peer(0).push_blocks(7, false);
net.run_until_sync().await;
Expand Down
2 changes: 1 addition & 1 deletion pallet/vortex-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ pub mod pallet {
if let Err(e) = Self::vtx_dist_offchain_worker(now) {
log::info!(
target: "vtx-dist",
"error happened in offchain worker at {:?}: {:?}",
"offchain worker not triggered at {:?}: {:?}",
now,
e,
);
Expand Down
46 changes: 19 additions & 27 deletions pallet/xrpl/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ mod self_contained_call {
#[test]
fn transact_validations() {
TestExt::<Test>::default().build().execute_with(|| {
// encoded call for: genesis_hash = 0x0, nonce = 0, max_block_number = 5, tip = 0, extrinsic = System::remark
// encoded call for: genesis_hash = 0x0, nonce = 0, max_block_number = 5, tip = 0, extrinsic = System::remark
let call = mock::RuntimeCall::System(frame_system::Call::remark { remark: Default::default() });
let tx_bytes = hex::decode("5916969036626990000000000000000000F236FD752B5E4C84810AB3D41A3C2580732102509540919FAACF9AB52146C9AA40DB68172D83777250B28E4679176E49CCDD9F81148E6106F6E98E7B21BFDFBFC3DEBA0EDED28A047AF9EA7C0965787472696E7369637D48303A303A353A303A35633933633236383339613137636235616366323765383961616330306639646433663531643161316161346234383266363930663634333633396665383732E1F1").unwrap();
assert_ok!(Xrpl::transact(frame_system::RawOrigin::None.into(), BoundedVec::truncate_from(tx_bytes.clone()), BoundedVec::default(), Box::new(call)));
});
let tx_bytes = hex::decode("5916969036626990000000000000000000F236FD752B5E4C84810AB3D41A3C2580732102509540919FAACF9AB52146C9AA40DB68172D83777250B28E4679176E49CCDD9F81148E6106F6E98E7B21BFDFBFC3DEBA0EDED28A047AF9EA7C0965787472696E7369637D48303A303A353A303A35633933633236383339613137636235616366323765383961616330306639646433663531643161316161346234383266363930663634333633396665383732E1F1").unwrap();
assert_ok!(Xrpl::transact(frame_system::RawOrigin::None.into(), BoundedVec::truncate_from(tx_bytes.clone()), BoundedVec::default(), Box::new(call)));
});
}

#[test]
fn extrinsic_cannot_perform_privileged_operations() {
TestExt::<Test>::default().build().execute_with(|| {
let call = mock::RuntimeCall::System(frame_system::Call::set_code { code: Default::default() });
// encoded call for: genesis_hash = 0x0, nonce = 0, max_block_number = 5, tip = 0, extrinsic = System::set_code
// encoded call for: genesis_hash = 0x0, nonce = 0, max_block_number = 5, tip = 0, extrinsic = System::set_code
let tx_bytes = hex::decode("5916969036626990000000000000000000F236FD752B5E4C84810AB3D41A3C2580732102509540919FAACF9AB52146C9AA40DB68172D83777250B28E4679176E49CCDD9F81148E6106F6E98E7B21BFDFBFC3DEBA0EDED28A047AF9EA7C0965787472696E7369637D48303A303A353A303A66633730373832313235333862623238393633373338393034303237373630313464393765303033656136393430303533303538386134383434393662333337E1F1").unwrap();

// executing xrpl encoded transaction fails since caller is not root/sudo account
Expand Down Expand Up @@ -69,8 +69,6 @@ mod self_contained_call {
});
}

// TODO Fix this once e2e tests are building
#[ignore]
#[test]
fn validate_nonce_too_high() {
TestExt::<Test>::default()
Expand All @@ -80,10 +78,10 @@ mod self_contained_call {
let call = mock::RuntimeCall::System(frame_system::Call::remark { remark: b"Mischief Managed".to_vec() });

// encoded call for: genesis_hash = 0x0, nonce = 5, max_block_number = 5, tip = 0, extrinsic = System::remark; validates nonce too high
let tx_bytes = hex::decode("5916969036626990000000000000000000F236FD752B5E4C84810AB3D41A3C2580732102509540919FAACF9AB52146C9AA40DB68172D83777250B28E4679176E49CCDD9F81148E6106F6E98E7B21BFDFBFC3DEBA0EDED28A047AF9EA7C0965787472696E7369637D87303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303A353A353A303A33623832663037383031653632636437383966316233636333353936383236313436613163353136666165613766633633333263643362323563646666316331E1F1").unwrap();
let tx_bytes = hex::decode("5916969036626990000000000000000000F236FD752B5E4C84810AB3D41A3C2580732102509540919FAACF9AB52146C9AA40DB68172D83777250B28E4679176E49CCDD9F81148E6106F6E98E7B21BFDFBFC3DEBA0EDED28A047AF9EA7C0965787472696E7369637D87303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303A353A353A303A33376635623466363237376431393362336134663037666135636538373239626137366235343735366238653066616539313531316264313830333032333265E1F1").unwrap();
let xt: mock::UncheckedExtrinsicT = fp_self_contained::UncheckedExtrinsic::new_unsigned(mock::RuntimeCall::Xrpl(crate::Call::transact {
encoded_msg: BoundedVec::truncate_from(tx_bytes.clone()),
signature: BoundedVec::truncate_from(hex::decode("3045022100BD4846922C600DEDE58A0B1E15D728671538209DBE6A5A03ECE3C9731D7F5068022027FC270D8DE1FCBE3D7B76931BF1980F0E4BCDA6A764FC76E659620AE91C7841").unwrap()),
signature: BoundedVec::truncate_from(hex::decode("3045022100C17C9D3D04DB3B77BDA2F8C91B8A30E0E28CC324FAE88EE54A1E3A8A2CA7BF1B02201BCBBB1A66695CFEA0BA3216BE06DD026D520A05E14960C047AB9986152FB35F").unwrap()),
call: Box::new(call.clone()),
}));

Expand Down Expand Up @@ -111,8 +109,8 @@ mod self_contained_call {

// validate self contained extrinsic fails, call provided is not signed hashed extrinsic in memo data
let xt: mock::UncheckedExtrinsicT = fp_self_contained::UncheckedExtrinsic::new_unsigned(mock::RuntimeCall::Xrpl(crate::Call::transact {
encoded_msg: BoundedVec::truncate_from(hex::decode("5916969036626990000000000000000000F236FD752B5E4C84810AB3D41A3C2580732102509540919FAACF9AB52146C9AA40DB68172D83777250B28E4679176E49CCDD9F81148E6106F6E98E7B21BFDFBFC3DEBA0EDED28A047AF9EA7C0965787472696E7369637D0A303A303A353A303A3030E1F1").unwrap()),
signature: BoundedVec::truncate_from(hex::decode("304502210081C0EFD0B5C85AC8C20765B95B44DCD0891619E83529A63A2350907B341EE168022006365C3AB530A1D529606D6EDDE18C76ECF42334FF0DC2140AD392C20305F898").unwrap()),
encoded_msg: BoundedVec::truncate_from(hex::decode("5916969036626990000000000000000000F236FD752B5E4C84810AB3D41A3C2580732102509540919FAACF9AB52146C9AA40DB68172D83777250B28E4679176E49CCDD9F81148E6106F6E98E7B21BFDFBFC3DEBA0EDED28A047AF9EA7C0965787472696E7369637D87303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303A303A353A303A33376635623466363237376431393362336134663037666135636538373239626137366235343735366238653066616539313531316264313830333032333265E1F1").unwrap()),
signature: BoundedVec::truncate_from(hex::decode("304402205CD628B33CD2A89D735EBC139F21A3F2F138F7D687BBAF3E2CDFBBF8951919DC02204B65FC7FF3C2C1B1EEF10186CF6BDAA1C96E8F0814099EE5811C12F65E26A81E").unwrap()),
call: Box::new(call.clone()),
}));
assert_err!(
Expand All @@ -122,8 +120,6 @@ mod self_contained_call {
});
}

// TODO Fix this once e2e tests are building
#[ignore]
#[test]
fn validate_transaction_signature() {
TestExt::<Test>::default()
Expand All @@ -133,7 +129,7 @@ mod self_contained_call {
let call = mock::RuntimeCall::System(frame_system::Call::remark { remark: b"Mischief Managed".to_vec() });

// encoded call for: genesis_hash = 0x0, nonce = 0, max_block_number = 5, tip = 0, extrinsic = System::remark
let tx_bytes = hex::decode("5916969036626990000000000000000000F236FD752B5E4C84810AB3D41A3C2580732102509540919FAACF9AB52146C9AA40DB68172D83777250B28E4679176E49CCDD9F81148E6106F6E98E7B21BFDFBFC3DEBA0EDED28A047AF9EA7C0965787472696E7369637D87303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303A303A353A303A33623832663037383031653632636437383966316233636333353936383236313436613163353136666165613766633633333263643362323563646666316331E1F1").unwrap();
let tx_bytes = hex::decode("5916969036626990000000000000000000F236FD752B5E4C84810AB3D41A3C2580732102509540919FAACF9AB52146C9AA40DB68172D83777250B28E4679176E49CCDD9F81148E6106F6E98E7B21BFDFBFC3DEBA0EDED28A047AF9EA7C0965787472696E7369637D87303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303A303A353A303A33376635623466363237376431393362336134663037666135636538373239626137366235343735366238653066616539313531316264313830333032333265E1F1").unwrap();

// validate self contained extrinsic is invalid (no signature)
let xt: mock::UncheckedExtrinsicT = fp_self_contained::UncheckedExtrinsic::new_unsigned(mock::RuntimeCall::Xrpl(crate::Call::transact {
Expand All @@ -160,7 +156,7 @@ mod self_contained_call {
// validate self contained extrinsic fails, user does not have funds to pay for transaction (corrected signature)
let xt: mock::UncheckedExtrinsicT = fp_self_contained::UncheckedExtrinsic::new_unsigned(mock::RuntimeCall::Xrpl(crate::Call::transact {
encoded_msg: BoundedVec::truncate_from(tx_bytes.clone()),
signature: BoundedVec::truncate_from(hex::decode("3045022100F21BB8B86C394E5A383881E3EFA7D2879D2E66E76174F7494C580B402643F45E02200DAB3D5E3B39E61E1020240BA718761EE9EFF148DFBAEC288EFFB4E3FD97DA1D").unwrap()),
signature: BoundedVec::truncate_from(hex::decode("3045022100AB93610B5A278148E75CC28E8308B963C6439B906D4F5EA9A38BA01567D061B1022021A5D789AD9D98BA6B63FD19676FF2ED72071C14BD8FE1745E72F769E03E005D").unwrap()),
call: Box::new(call.clone()),
}));
assert_err!(
Expand All @@ -176,8 +172,6 @@ mod self_contained_call {
});
}

// TODO Fix this once e2e tests are building
#[ignore]
#[test]
fn ecdsa_system_remark_extrinsic_from_message_success() {
TestExt::<Test>::default()
Expand All @@ -186,9 +180,9 @@ mod self_contained_call {
.execute_with(|| {
let call = mock::RuntimeCall::System(frame_system::Call::remark { remark: b"Mischief Managed".to_vec() });

// encoded call for: genesis_hash = 0x0, nonce = 0, max_block_number = 5, tip = 0, extrinsic = System::remark
let tx_bytes = hex::decode("5916969036626990000000000000000000F236FD752B5E4C84810AB3D41A3C2580732102509540919FAACF9AB52146C9AA40DB68172D83777250B28E4679176E49CCDD9F81148E6106F6E98E7B21BFDFBFC3DEBA0EDED28A047AF9EA7C0965787472696E7369637D87303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303A303A353A303A33623832663037383031653632636437383966316233636333353936383236313436613163353136666165613766633633333263643362323563646666316331E1F1").unwrap();
let signature = hex::decode("3045022100F21BB8B86C394E5A383881E3EFA7D2879D2E66E76174F7494C580B402643F45E02200DAB3D5E3B39E61E1020240BA718761EE9EFF148DFBAEC288EFFB4E3FD97DA1D").unwrap();
// encoded call for: genesis_hash = 0x0, nonce = 0, max_block_number = 5, tip = 0, extrinsic = System::remark
let tx_bytes = hex::decode("5916969036626990000000000000000000F236FD752B5E4C84810AB3D41A3C2580732102509540919FAACF9AB52146C9AA40DB68172D83777250B28E4679176E49CCDD9F81148E6106F6E98E7B21BFDFBFC3DEBA0EDED28A047AF9EA7C0965787472696E7369637D87303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303A303A353A303A33376635623466363237376431393362336134663037666135636538373239626137366235343735366238653066616539313531316264313830333032333265E1F1").unwrap();
let signature = hex::decode("3045022100AB93610B5A278148E75CC28E8308B963C6439B906D4F5EA9A38BA01567D061B1022021A5D789AD9D98BA6B63FD19676FF2ED72071C14BD8FE1745E72F769E03E005D").unwrap();

// fund the user with XRP (to pay for tx fees)
let tx = XRPLTransaction::try_from(tx_bytes.as_bytes_ref()).unwrap();
Expand Down Expand Up @@ -231,7 +225,7 @@ mod self_contained_call {
System::assert_last_event(mock::RuntimeEvent::System(
frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: Weight::from_all(311_960_000),
weight: Weight::from_parts(396_839_240, 220_300_000),
class: DispatchClass::Normal,
pays_fee: Pays::Yes,
},
Expand All @@ -252,8 +246,6 @@ mod self_contained_call {
});
}

// TODO - enable once e2e ready?
#[ignore]
#[test]
fn ed25519_system_remark_extrinsic_from_message_success() {
TestExt::<Test>::default()
Expand All @@ -262,9 +254,9 @@ mod self_contained_call {
.execute_with(|| {
let call = mock::RuntimeCall::System(frame_system::Call::remark { remark: b"Mischief Managed".to_vec() });

// encoded call for: genesis_hash = 0x0, nonce = 0, max_block_number = 5, tip = 0, extrinsic = System::remark
let tx_bytes = hex::decode("5916969036626990000000000000000000F236FD752B5E4C84810AB3D41A3C25807321EDFB2A3A850B43E24D2700532EF1F9CCB2475DFF4F62B634B0C58845F23C26396581145116224CEF7355137BEBBA8E277A9BE18E0596E7F9EA7C0965787472696E7369637D87303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303A303A353A303A33623832663037383031653632636437383966316233636333353936383236313436613163353136666165613766633633333263643362323563646666316331E1F1").unwrap();
let signature = hex::decode("7B1FBDAC5A646259451329E9D57DD4C1D5AF5970F46232E893408001E762E9DB68E30E9E9D023229EAA290ACB6AFF1D527025161C7649DC61366C0574AC07A02").unwrap();
// encoded call for: genesis_hash = 0x0, nonce = 0, max_block_number = 5, tip = 0, extrinsic = System::remark
let tx_bytes = hex::decode("5916969036626990000000000000000000F236FD752B5E4C84810AB3D41A3C25807321EDFB2A3A850B43E24D2700532EF1F9CCB2475DFF4F62B634B0C58845F23C26396581145116224CEF7355137BEBBA8E277A9BE18E0596E7F9EA7C0965787472696E7369637D87303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303A303A353A303A33376635623466363237376431393362336134663037666135636538373239626137366235343735366238653066616539313531316264313830333032333265E1F1").unwrap();
let signature = hex::decode("81D0291D0D4CBCD9152F882E09F339F35022617D3BD2178AD8900FD12D8BD1DF69AB9AAD58BA44EF8FC14FA8DB4203272FE24CF5135D25EA5F8492B538C99201").unwrap();

// fund the user with XRP (to pay for tx fees)
let tx = XRPLTransaction::try_from(tx_bytes.as_bytes_ref()).unwrap();
Expand Down Expand Up @@ -307,7 +299,7 @@ mod self_contained_call {
System::assert_last_event(mock::RuntimeEvent::System(
frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: Weight::from_all(311_960_000),
weight: Weight::from_parts(396_839_240, 220_300_000),
class: DispatchClass::Normal,
pays_fee: Pays::Yes,
},
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ mod staking;

use staking::OnChainAccuracy;

pub mod migrations;
mod migrations;
mod weights;

use crate::impls::{
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/tests/evm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ fn call_with_fee_preferences_futurepass_proxy_extrinsic() {
RawOrigin::Signed(alice()).into(),
payment_asset,
alice(),
20_000_000_000_000_000
10_000_000_000_000_000
));

// add liquidity to the dex, this will allow for exchange internally when the call is made
Expand Down