Skip to content

Commit

Permalink
test: fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWaWaR committed Jul 30, 2021
1 parent 271261e commit eff7a22
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 13 deletions.
14 changes: 9 additions & 5 deletions ckb-sdk/src/rpc/client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use ckb_jsonrpc_types::{
BannedAddr, Block, BlockNumber, BlockTemplate, BlockView, CellWithStatus, ChainInfo, Consensus,
Cycle, EpochNumber, EpochView, ExtraLoggerConfig, HeaderView, JsonBytes, LocalNode,
MainLoggerConfig, OutPoint, RawTxPool, RemoteNode, Script, Timestamp, Transaction,
TransactionProof, TransactionWithStatus, TxPoolInfo, Uint64, Version,
MainLoggerConfig, OutPoint, OutputsValidator, RawTxPool, RemoteNode, Script, Timestamp,
Transaction, TransactionProof, TransactionWithStatus, TxPoolInfo, Uint64, Version,
};

use super::primitive;
Expand Down Expand Up @@ -108,7 +108,7 @@ jsonrpc!(pub struct RawHttpRpcClient {
pub fn ping_peers(&mut self) -> ();

// Pool
pub fn send_transaction(&mut self, tx: Transaction) -> H256;
pub fn send_transaction(&mut self, tx: Transaction, outputs_validator: Option<OutputsValidator>) -> H256;
pub fn tx_pool_info(&mut self) -> TxPoolInfo;
pub fn get_raw_tx_pool(&mut self, verbose: Option<bool>) -> RawTxPool;

Expand Down Expand Up @@ -330,9 +330,13 @@ impl HttpRpcClient {
}

// Pool
pub fn send_transaction(&mut self, tx: packed::Transaction) -> Result<H256, String> {
pub fn send_transaction(
&mut self,
tx: packed::Transaction,
outputs_validator: Option<OutputsValidator>,
) -> Result<H256, String> {
self.client
.send_transaction(tx.into())
.send_transaction(tx.into(), outputs_validator)
.map_err(|err| err.to_string())
}
pub fn tx_pool_info(&mut self) -> Result<types::TxPoolInfo, String> {
Expand Down
7 changes: 4 additions & 3 deletions ckb-sdk/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,17 @@ impl<'a> MockTransactionHelper<'a> {
max_cycle: Cycle,
loader: L,
) -> Result<Cycle, String> {
// FIXME: use the right TxVerifyEnv & Consensus
let (consensus, tx_env) = {
let epoch = EpochNumberWithFraction::new(300, 0, 1);
let enable_epoch_number = 200;
let commit_epoch_number = 200 + 100;
let epoch = EpochNumberWithFraction::new(commit_epoch_number, 0, 1);
let header = HeaderView::new_advanced_builder()
.epoch(epoch.pack())
.build();
let tx_env = TxVerifyEnv::new_commit(&header);
let hardfork_switch = HardForkSwitch::new_without_any_enabled()
.as_builder()
.rfc_0232(200)
.rfc_0232(enable_epoch_number)
.build()
.unwrap();
let consensus = ConsensusBuilder::default()
Expand Down
2 changes: 1 addition & 1 deletion src/subcommands/dao/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub(crate) fn send_transaction(
);
}

let resp = rpc_client.send_transaction(transaction.data())?;
let resp = rpc_client.send_transaction(transaction.data(), None)?;
Ok(Output::new_output(resp))
}

Expand Down
5 changes: 4 additions & 1 deletion src/subcommands/mock_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,10 @@ impl<'a> CliSubCommand for MockTxSubCommand<'a> {
let (mock_tx, _cycle) = complete_tx(m, false, true)?;
let resp = self
.rpc_client
.send_transaction(mock_tx.core_transaction().data())
.send_transaction(
mock_tx.core_transaction().data(),
Some(json_types::OutputsValidator::Passthrough),
)
.map_err(|err| format!("Send transaction error: {}", err))?;
Ok(Output::new_output(resp))
}
Expand Down
2 changes: 1 addition & 1 deletion src/subcommands/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ impl<'a> CliSubCommand for TxSubCommand<'a> {
}
let resp = self
.rpc_client
.send_transaction(tx.data())
.send_transaction(tx.data(), Some(json_types::OutputsValidator::Passthrough))
.map_err(|err| format!("Send transaction error: {}", err))?;
Ok(Output::new_output(resp))
}
Expand Down
7 changes: 6 additions & 1 deletion src/subcommands/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,14 @@ impl<'a> WalletSubCommand<'a> {
helper.add_signature(lock_arg, signature)?;
}
let tx = helper.build_tx(&mut get_live_cell_fn, skip_check)?;
let outputs_validator = if is_type_id || skip_check || skip_check_to_address {
Some(json_types::OutputsValidator::Passthrough)
} else {
None
};
let tx_hash = self
.rpc_client
.send_transaction(tx.data())
.send_transaction(tx.data(), outputs_validator)
.map_err(|err| format!("Send transaction error: {}", err))?;
assert_eq!(tx.hash(), tx_hash.pack());
Ok(tx)
Expand Down
6 changes: 5 additions & 1 deletion test/src/spec/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ impl Spec for Plugin {

let output = setup.cli(&format!("wallet transfer --from-account {} --to-address ckt1qyqt8xaupvm8837nv3gtc9x0ekkj64vud3jq5t63cs --capacity 1000 --tx-fee 0.1", Miner::address()));
// Means the signature is filled but is wrong: https://github.com/nervosnetwork/ckb-system-scripts/wiki/Error-codes
assert!(output.contains("ValidationFailure(-31)"));
assert!(
output.contains("cause: ValidationFailure: see the error code -31 in the page"),
"{}",
output
);

let output = setup
.cli("account extended-address --lock-arg 0xef8484612fefa725097ecef6dce0e19e0d77fb79");
Expand Down

0 comments on commit eff7a22

Please sign in to comment.