Skip to content

Commit 5f9d6f5

Browse files
committed
Add testmempoolaccept test and update structs
Add a test for `testmempoolaccept` and implement all the changes to the returned fields in versions 21, 22, 25 and 29. Update the types table
1 parent 60dbb35 commit 5f9d6f5

File tree

29 files changed

+803
-44
lines changed

29 files changed

+803
-44
lines changed

integration_test/tests/raw_transactions.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,34 @@ fn raw_transactions__submit_package__modelled() {
382382
}
383383

384384
#[test]
385-
#[cfg(feature = "TODO")]
386-
fn raw_transactions__test_mempool_accept__modelled() {}
385+
fn raw_transactions__test_mempool_accept__modelled() {
386+
let node = Node::with_wallet(Wallet::Default, &[]);
387+
node.fund_wallet();
388+
let tx = create_a_raw_transaction(&node);
389+
390+
// Sign (but don't broadcast).
391+
let signed: SignRawTransaction = node
392+
.client
393+
.sign_raw_transaction_with_wallet(&tx)
394+
.expect("signrawtransactionwithwallet");
395+
let signed_model: mtype::SignRawTransaction = signed
396+
.into_model()
397+
.expect("SignRawTransaction into model");
398+
let signed_tx = signed_model.tx;
399+
400+
// Call testmempoolaccept with the valid (not yet broadcast) transaction.
401+
let json: TestMempoolAccept = node
402+
.client
403+
.test_mempool_accept(&[signed_tx.clone()])
404+
.expect("testmempoolaccept");
405+
let model: mtype::TestMempoolAccept = json
406+
.into_model()
407+
.expect("TestMempoolAccept into model");
408+
assert_eq!(model.results.len(), 1);
409+
let res = &model.results[0];
410+
assert_eq!(res.txid, signed_tx.compute_txid());
411+
assert!(res.allowed, "fresh signed tx should be allowed");
412+
}
387413

388414
#[test]
389415
#[cfg(not(feature = "v17"))] // utxoupdatepsbt was added in v0.18.

types/src/model/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub use self::{
4444
DecodeScript, DescriptorProcessPsbt, FinalizePsbt, FundRawTransaction, GetRawTransaction,
4545
GetRawTransactionVerbose, JoinPsbts, MempoolAcceptance, SendRawTransaction, SignFail,
4646
SignRawTransaction, SubmitPackage, SubmitPackageTxResult, SubmitPackageTxResultFees,
47-
TestMempoolAccept, UtxoUpdatePsbt,
47+
TestMempoolAccept, UtxoUpdatePsbt, MempoolAcceptanceFees
4848
},
4949
util::{
5050
CreateMultisig, DeriveAddresses, DeriveAddressesMultipath, EstimateSmartFee,

types/src/model/raw_transactions.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,37 @@ pub struct TestMempoolAccept {
272272
pub results: Vec<MempoolAcceptance>,
273273
}
274274

275-
/// Represents a single mempool acceptance test result.
275+
/// Models a single mempool acceptance test result. Returned as part of `testmempoolaccept`.
276276
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
277277
#[serde(deny_unknown_fields)]
278278
pub struct MempoolAcceptance {
279279
/// The transaction ID.
280280
pub txid: Txid,
281+
/// The transaction witness hash in hex.
282+
pub wtxid: Option<Wtxid>,
281283
/// If the mempool allows this transaction to be inserted.
282284
pub allowed: bool,
285+
/// Virtual transaction size as defined in BIP 141 (only present when 'allowed' is true).
286+
pub vsize: Option<u32>,
287+
/// Transaction fee in BTC (only present if 'allowed' is true).
288+
pub fees: Option<MempoolAcceptanceFees>,
283289
/// Rejection string (only present when 'allowed' is false).
284290
pub reject_reason: Option<String>,
291+
/// Rejection details (only present when 'allowed' is false and rejection details exist)
292+
pub reject_details: Option<String>,
293+
}
294+
295+
/// Models the fees field. Returned as part of `testmempoolaccept`.
296+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
297+
#[serde(deny_unknown_fields)]
298+
pub struct MempoolAcceptanceFees {
299+
/// Transaction fee in BTC.
300+
pub base: Amount,
301+
/// The effective feerate in BTC per KvB. May differ from the base feerate if, for example, there
302+
/// are modified fees from `prioritisetransaction` or a package feerate was used.
303+
pub effective_feerate: Option<FeeRate>,
304+
/// Transactions whose fees and vsizes are included in `effective_feerate`.
305+
pub effective_includes: Option<Vec<Wtxid>>,
285306
}
286307

287308
/// Models the result of JSON-RPC method `utxoupdatepsbt;`.

types/src/v17/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
//! | sendrawtransaction | version + model | |
129129
//! | signrawtransaction | version + model | |
130130
//! | signrawtransactionwithkey | version + model | |
131-
//! | testmempoolaccept | version + model | UNTESTED |
131+
//! | testmempoolaccept | version + model | |
132132
//!
133133
//! </details>
134134
//!

types/src/v17/raw_transactions/into.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ impl SignFail {
449449
impl TestMempoolAccept {
450450
/// Converts version specific type to a version nonspecific, more strongly typed type.
451451
pub fn into_model(self) -> Result<model::TestMempoolAccept, hex::HexToArrayError> {
452-
let results = self.results.into_iter().map(|r| r.into_model()).collect::<Result<_, _>>()?;
452+
let results = self.0.into_iter().map(|r| r.into_model()).collect::<Result<_, _>>()?;
453453

454454
Ok(model::TestMempoolAccept { results })
455455
}
@@ -462,8 +462,12 @@ impl MempoolAcceptance {
462462

463463
Ok(model::MempoolAcceptance {
464464
txid,
465+
wtxid: None, // v22 and later only.
465466
allowed: self.allowed,
467+
vsize: None, // v21 and later only.
468+
fees: None, // v21 and later only.
466469
reject_reason: self.reject_reason,
470+
reject_details: None, // v29 and later only.
467471
})
468472
}
469473
}

types/src/v17/raw_transactions/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -451,14 +451,9 @@ pub struct SignFail {
451451
/// > 2. allowhighfees (boolean, optional, default=false) Allow high fees
452452
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
453453
#[serde(deny_unknown_fields)]
454-
pub struct TestMempoolAccept {
455-
/// Array of test results for each raw transaction in the input array.
456-
///
457-
/// Length is exactly one for now.
458-
pub results: Vec<MempoolAcceptance>,
459-
}
454+
pub struct TestMempoolAccept(pub Vec<MempoolAcceptance>);
460455

461-
/// Represents a single mempool acceptance test result.
456+
/// Represents a single mempool acceptance test result, returned as part of `testmempoolaccept`.
462457
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
463458
#[serde(deny_unknown_fields)]
464459
pub struct MempoolAcceptance {

types/src/v18/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
//! | joinpsbts | version + model | UNTESTED |
133133
//! | sendrawtransaction | version + model | |
134134
//! | signrawtransactionwithkey | version + model | |
135-
//! | testmempoolaccept | version + model | UNTESTED |
135+
//! | testmempoolaccept | version + model | |
136136
//! | utxoupdatepsbt | version + model | UNTESTED |
137137
//!
138138
//! </details>

types/src/v19/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
//! | joinpsbts | version + model | UNTESTED |
133133
//! | sendrawtransaction | version + model | |
134134
//! | signrawtransactionwithkey | version + model | |
135-
//! | testmempoolaccept | version + model | UNTESTED |
135+
//! | testmempoolaccept | version + model | |
136136
//! | utxoupdatepsbt | version + model | UNTESTED |
137137
//!
138138
//! </details>

types/src/v20/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
//! | joinpsbts | version + model | UNTESTED |
134134
//! | sendrawtransaction | version + model | |
135135
//! | signrawtransactionwithkey | version + model | |
136-
//! | testmempoolaccept | version + model | UNTESTED |
136+
//! | testmempoolaccept | version + model | |
137137
//! | utxoupdatepsbt | version + model | UNTESTED |
138138
//!
139139
//! </details>

types/src/v21/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
//! | joinpsbts | version + model | UNTESTED |
135135
//! | sendrawtransaction | version + model | |
136136
//! | signrawtransactionwithkey | version + model | |
137-
//! | testmempoolaccept | version + model | UNTESTED |
137+
//! | testmempoolaccept | version + model | |
138138
//! | utxoupdatepsbt | version + model | UNTESTED |
139139
//!
140140
//! </details>
@@ -235,6 +235,7 @@
235235
mod blockchain;
236236
mod generating;
237237
mod network;
238+
mod raw_transactions;
238239
mod util;
239240
mod wallet;
240241

@@ -247,6 +248,9 @@ pub use self::{
247248
},
248249
generating::GenerateBlock,
249250
network::{GetNetworkInfo, GetPeerInfo, PeerInfo},
251+
raw_transactions::{
252+
MempoolAcceptance, MempoolAcceptanceError, TestMempoolAccept, TestMempoolAcceptError,
253+
},
250254
util::{GetIndexInfo, GetIndexInfoName},
251255
wallet::{
252256
ImportDescriptors, ImportDescriptorsResult, PsbtBumpFee, PsbtBumpFeeError, Send, SendError,
@@ -282,7 +286,7 @@ pub use crate::{
282286
Locked, PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
283287
RescanBlockchain, ScriptType, SendMany, SendRawTransaction, SendToAddress,
284288
SetNetworkActive, SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
285-
SignRawTransactionError, SoftforkReject, TestMempoolAccept, TransactionCategory,
289+
SignRawTransactionError, SoftforkReject, TransactionCategory,
286290
UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage,
287291
VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt,
288292
WitnessUtxo,

0 commit comments

Comments
 (0)