Skip to content

WIP chain-impl-mockchain proptest #655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions cardano-legacy-address/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ chain-ser = {path = "../chain-ser"}

criterion = { version = "0.3.0", optional = true }

proptest = { git = "https://github.com/input-output-hk/proptest.git", optional = true }
test-strategy = { version = "0.1", optional = true }

[features]
default = []
with-bench = ["criterion"]
property-test-api = ["proptest", "test-strategy"]

[[bench]]
harness = false
Expand Down
6 changes: 5 additions & 1 deletion cardano-legacy-address/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ fn hash_spending_data(xpub: &XPub, attrs: &Attributes) -> [u8; 28] {

/// A valid cardano Address that is displayed in base58
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
pub struct Addr(Vec<u8>);
#[cfg_attr(
any(test, feature = "property-test-api"),
derive(test_strategy::Arbitrary)
)]
pub struct Addr(#[cfg_attr(any(test, feature = "property-test-api"), any(proptest::collection::size_range(ed25519_bip32::XPUB_SIZE).lift()))] Vec<u8>);

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AddressMatchXPub {
Expand Down
4 changes: 4 additions & 0 deletions chain-addr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ pub enum Kind {

/// Kind Type of an address
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(
any(test, feature = "property-test-api"),
derive(test_strategy::Arbitrary)
)]
pub enum KindType {
Single,
Group,
Expand Down
11 changes: 11 additions & 0 deletions chain-crypto/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,15 @@ mod test {
.boxed()
}
}

impl<A: AsymmetricKey> Arbitrary for SecretKey<A> {
type Parameters = ();
type Strategy = BoxedStrategy<SecretKey<A>>;

fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
any::<(TestCryptoGen, u32)>()
.prop_map(|(gen, idx)| SecretKey::generate(gen.get_rng(idx)))
.boxed()
}
}
}
41 changes: 41 additions & 0 deletions chain-crypto/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,44 @@ pub fn public_key_strategy<A: AsymmetricKey>() -> impl Strategy<Value = PublicKe
any::<(TestCryptoGen, u32)>()
.prop_map(|(gen, idx)| SecretKey::<A>::generate(gen.get_rng(idx)).to_public())
}

impl<H: digest::DigestAlg, T> proptest::arbitrary::Arbitrary for digest::DigestOf<H, T> {
type Strategy = BoxedStrategy<digest::DigestOf<H, T>>;
type Parameters = ();

fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
any::<Vec<u8>>()
.prop_map(|bytes| digest::DigestOf::<H, Vec<u8>>::digest(&bytes).coerce())
.boxed()
}
}

impl proptest::arbitrary::Arbitrary for Blake2b256 {
type Strategy = BoxedStrategy<Self>;
type Parameters = ();

fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
any::<[u8; Self::HASH_SIZE]>()
.prop_map(|bytes| Self::try_from_slice(&bytes).unwrap())
.boxed()
}
}

impl<T, A> proptest::arbitrary::Arbitrary for Signature<T, A>
where
A: VerificationAlgorithm + 'static,
A::Signature: Send,
T: Send + 'static,
{
type Strategy = BoxedStrategy<Self>;
type Parameters = ();

fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
use proptest::collection::vec;
// generic parameters may not be used in const operations
// type parameters may not be used in const expressions
vec(any::<u8>(), A::SIGNATURE_SIZE)
.prop_map(|bytes| Self::from_binary(&bytes).unwrap())
.boxed()
}
}
12 changes: 8 additions & 4 deletions chain-impl-mockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ strum = "0.21.0"
strum_macros = "0.21.0"
hex = { version = "0.4.2", default-features = false, features = [ "std" ] }
quickcheck = { version = "0.9", optional = true }
quickcheck_macros = { version = "0.9", optional = true }
ed25519-bip32 = { version = "0.4", optional = true }
thiserror = "1.0"
lazy_static = { version = "1.3.0", optional = true }
Expand All @@ -30,27 +29,32 @@ rand_chacha = { version = "0.3", optional = true }
rayon = "1.5.0"
criterion = { version = "0.3.0", optional = true }
rand = "0.8"
proptest = { git = "https://github.com/input-output-hk/proptest.git", optional = true }
test-strategy = { version = "0.1", optional = true }

[features]
property-test-api = [
"chain-crypto/property-test-api",
"chain-time/property-test-api",
"chain-addr/property-test-api",
"quickcheck",
"quickcheck_macros",
"lazy_static",
"rand_chacha",
"ed25519-bip32"]
"ed25519-bip32",
"proptest",
"test-strategy"]
with-bench = ["criterion","property-test-api"]
evm = ["chain-evm"]

[dev-dependencies]
quickcheck = "0.9"
quickcheck_macros = "0.9"
proptest = { git = "https://github.com/input-output-hk/proptest.git" }
test-strategy = "0.1"
chain-core = { path = "../chain-core"}
chain-crypto = { path = "../chain-crypto", features=["property-test-api"]}
chain-time = { path = "../chain-time", features=["property-test-api"]}
chain-addr = { path = "../chain-addr", features=["property-test-api"]}
cardano-legacy-address = { path = "../cardano-legacy-address", features = ["property-test-api"] }
ed25519-bip32 = "0.4"
rand_chacha = "0.3"
lazy_static = "1.3.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
xx e09a705689b01a3d9614cffcb42fa70a56c61c1b3386beebc1c7c54edefffab8 # shrinks to input = _AddRewardsArgs { account_state_no_reward: AccountState { counter: SpendingCounter(0), delegation: NonDelegated, value: Value(0), last_rewards: LastRewards { epoch: 1, reward: Value(1) }, extra: () }, value: Value(0) }
xx 447db2634032facedd7577335b8c534572638ee886279f92103b000438b56f3d # shrinks to input = _AccountStateIsConsistentArgs { account_state: AccountState { counter: SpendingCounter(0), delegation: NonDelegated, value: Value(0), last_rewards: LastRewards { epoch: 0, reward: Value(1) }, extra: () }, operations: ArbitraryOperationChain([]) }
7 changes: 7 additions & 0 deletions chain-impl-mockchain/proptest-regressions/block/test.txt

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions chain-impl-mockchain/proptest-regressions/fee.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
xx 3dc719c99d00969fd03e8e1d1f8d247bb5454706b24c88a7fa30c3afd0d3f412 # shrinks to input = _LinearFeeCertificateCalculationArgs { certificate: PoolRetirement(PoolRetirement { pool_id: $hash_ty(0x8257a87f25ab75cb5f6ba506adb59cf1764365e93f5e7400c3ed1fe3496f1e2f), retirement_time: TimeOffsetSeconds(DurationSeconds(7448678820576350356)) }), inputs: 141, outputs: 204, fee: LinearFee { constant: 84037131145763882, coefficient: 4127535450679263578, certificate: 16808812788604336532, per_certificate_fees: PerCertificateFee { certificate_pool_registration: Some(8974887929408341596), certificate_stake_delegation: None, certificate_owner_stake_delegation: None }, per_vote_certificate_fees: PerVoteCertificateFee { certificate_vote_plan: Some(8783595777020599411), certificate_vote_cast: None } }, per_certificate_fees: PerCertificateFee { certificate_pool_registration: Some(13700089163430403858), certificate_stake_delegation: Some(2491635649483717791), certificate_owner_stake_delegation: Some(6568572915426812252) }, per_vote_certificate_fees: PerVoteCertificateFee { certificate_vote_plan: Some(8482191035474706181), certificate_vote_cast: Some(8792449183706279014) } }
9 changes: 9 additions & 0 deletions chain-impl-mockchain/proptest-regressions/fragment/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
xx f779cfcda49afe7b4e8a1522ddc9df2b628f8287d27619f92082ed7bf07e872a # shrinks to input = _InitialEntsSerializationBijectionArgs { config_params: ConfigParams([LinearFee(LinearFee { constant: 0, coefficient: 0, certificate: 0, per_certificate_fees: PerCertificateFee { certificate_pool_registration: None, certificate_stake_delegation: None, certificate_owner_stake_delegation: None }, per_vote_certificate_fees: PerVoteCertificateFee { certificate_vote_plan: None, certificate_vote_cast: Some(1) } })]) }
xx 584bc2dc033882ab5b88a47af5bf2159deb77e6cc2e017069b5d34a343430f81 # shrinks to input = _FragmentRawBijectionArgs { b: OwnerStakeDelegation(Transaction { payload: [8, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], nb_inputs: 0, nb_outputs: 0, valid_until: BlockDate { epoch: 1, slot_id: 0 }, nb_witnesses: 0, total_input_value: Ok(Value(0)), total_output_value: Ok(Value(0)) }) }
xx 0ca2daad13262f5e0a8786a0365cf319b8cf645828481f44dc1898c5e43df8e5 # shrinks to input = _FragmentSerializationBijectionArgs { b: StakeDelegation(Transaction { payload: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], nb_inputs: 0, nb_outputs: 0, valid_until: BlockDate { epoch: 1, slot_id: 0 }, nb_witnesses: 0, total_input_value: Ok(Value(0)), total_output_value: Ok(Value(0)) }) }
7 changes: 7 additions & 0 deletions chain-impl-mockchain/proptest-regressions/ledger/ledger.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
xx d60c59631a4d512ed4aead7831583a4f1a6729ee20e7f4fa13b98c0d442d6615 # shrinks to input = _TestInternalApplyTransactionFundsWereTransferedArgs { sender_address: AddressData { public_key: ec612c23485d5afa5a9cd700416e1d09f12747dcf970812c47de8befb2c256b8, spending_counter: None, address: Address(Test, Single(ec612c23485d5afa5a9cd700416e1d09f12747dcf970812c47de8befb2c256b8)) }, reciever_address: AddressData { public_key: ec612c23485d5afa5a9cd700416e1d09f12747dcf970812c47de8befb2c256b8, spending_counter: None, address: Address(Test, Single(ec612c23485d5afa5a9cd700416e1d09f12747dcf970812c47de8befb2c256b8)) } }
7 changes: 7 additions & 0 deletions chain-impl-mockchain/proptest-regressions/ledger/pots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
xx 24cfaf93ff3cb9cbfd3da49403bce08b74535932f91dc059c2121f2f380c8d0f # shrinks to input = _TreasuryAddArgs { pots: Pots { fees: Value(0), treasury: Treasury(Value(13107457562879298199)), rewards: Value(0) }, value: Value(5339286510830253417) }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
xx df8b322ea4a7e4ccf2bcf7660d070a40b57bd7305d30ac987c586bb539feeba2 # shrinks to input = _LedgerVerifiesFaucetDiscriminationArgs { arbitrary_faucet_disc: Production, arbitrary_faucet_address_kind: Script, arbitrary_ledger_disc: Production }
xx d44a0cf703cc32fdd0c0980c964286088e936d6e8bbc811330a8222dc6f0faa8 # shrinks to input = _LedgerVerifiesTransactionDiscriminationArgs { arbitrary_input_disc: Production, arbitrary_output_disc: Production, arbitrary_input_address_kind: Single, arbitrary_output_address_kind: Script }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
xx 282ba5a0bd548585b46e68632d5ca4dbc017bf3ddf5508f7de77c50e9a4c5431 # shrinks to input = _LedgerAdoptSettingsFromUpdateProposalArgs { update_proposal_data: UpdateProposalData { leaders: [BftLeaderId(2e5d30506528a9d2499eec72f80c52f29683d952ebda0b37124b1706344b0a73)], proposal: SignedUpdateProposal { proposal: UpdateProposalWithProposer { proposal: UpdateProposal { changes: ConfigParams([]) }, proposer_id: BftLeaderId(2e5d30506528a9d2499eec72f80c52f29683d952ebda0b37124b1706344b0a73) } }, proposal_id: Hash(Blake2b256(0xd85f698bb43038619b209676144afd82675fae79a64af03b80eb9719c02c70ec)), votes: [] } }
7 changes: 7 additions & 0 deletions chain-impl-mockchain/proptest-regressions/rewards.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
xx 45efc80baa8a4a5447f550e41d50602f84c6229beff60279451470e07a8a2ada # shrinks to input = _TaxCutFullyAccountedArgs { v: Value(6644475504521289437), treasury_tax: TaxType { fixed: Value(0), ratio: Ratio { numerator: 51212825857, denominator: 1 }, max_limit: None } }

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
xx 08e03ada52d9d3683cc429541c2d8b1c8750903779325aa4b559777a4abb8f8e # shrinks to input = _AssignAccountValueIsConsitentWithStakeDistributionArgs { account_identifier: Identifier(ec612c23485d5afa5a9cd700416e1d09f12747dcf970812c47de8befb2c256b8), delegation_type: Ratio(DelegationRatio { parts: 8, pools: [] }), value: Stake(1) }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
xx 22277a863c8ded231683e5858674bc85f6670fa064c33c59a6cf0d47d80d7cee # shrinks to input = _StakeOwnerDelegationTxEncodeDecodeArgs { transaction: Transaction { payload: [8, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], nb_inputs: 0, nb_outputs: 0, valid_until: BlockDate { epoch: 1, slot_id: 0 }, nb_witnesses: 0, total_input_value: Ok(Value(0)), total_output_value: Ok(Value(0)) } }
7 changes: 7 additions & 0 deletions chain-impl-mockchain/proptest-regressions/update.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
xx 4642d80469dec0525b5af24e14ada6222305a2ae797c3127bfa04a810a2ca1c6 # shrinks to input = _UpdateProposalSerializeDeserializeBijectionArgs { update_proposal: UpdateProposal { changes: ConfigParams([LinearFee(LinearFee { constant: 0, coefficient: 0, certificate: 0, per_certificate_fees: PerCertificateFee { certificate_pool_registration: None, certificate_stake_delegation: None, certificate_owner_stake_delegation: None }, per_vote_certificate_fees: PerVoteCertificateFee { certificate_vote_plan: None, certificate_vote_cast: Some(1) } })]) } }
7 changes: 7 additions & 0 deletions chain-impl-mockchain/proptest-regressions/utxo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
xx 19270d1f1aee9a25c6507114a1ecca479baf33abdaeeb9304a55ad1048e2010a # shrinks to input = _TransactionUnspentRemoveArgs { outputs: ArbitraryTransactionOutputs { utxos: {0: Output { address: Address(Test, Single(b1d12215b806dce8f7d9bf818bcd6f4bfbbbc1f1c2a0987bb75f5f2624ad1f61)), value: Value(6105) }}, idx_to_remove: 255 } }
9 changes: 8 additions & 1 deletion chain-impl-mockchain/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ pub type Witness = Signature<WitnessAccountData, AccountAlg>;

/// Account Identifier (also used as Public Key)
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Identifier(PublicKey<AccountAlg>);
#[cfg_attr(
any(test, feature = "property-test-api"),
derive(test_strategy::Arbitrary)
)]
pub struct Identifier(
#[cfg_attr(any(test, feature = "property-test-api"), strategy(chain_crypto::testing::public_key_strategy::<AccountAlg>()))]
PublicKey<AccountAlg>,
);

impl From<PublicKey<AccountAlg>> for Identifier {
fn from(pk: PublicKey<AccountAlg>) -> Self {
Expand Down
Loading