From f7f0dfde51996e58dd9f45ce8835dfb72e817fa9 Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Thu, 20 Jun 2019 11:59:23 +0200 Subject: [PATCH] Update and fix quickcheck fuzz test --- quickcheck/aefate_code_eqc.erl | 27 +++++++++++++++------------ src/aeb_fate_generate_ops.erl | 4 ++-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/quickcheck/aefate_code_eqc.erl b/quickcheck/aefate_code_eqc.erl index 2c72a21..7938d7b 100644 --- a/quickcheck/aefate_code_eqc.erl +++ b/quickcheck/aefate_code_eqc.erl @@ -46,20 +46,23 @@ prop_fail_serializes() -> ?FORALL(FateCode, fate_code(Failure), ?FORALL(Binary, catch aeb_fate_code:serialize(FateCode), is_binary(Binary)))) - =/= true} || Failure <- [1,2,3,4, 5] ]). + =/= true} || Failure <- [1, 2, 3, 4, 5] ]). prop_fuzz() -> in_parallel( ?FORALL(Binary, ?LET(FateCode, fate_code(0), aeb_fate_code:serialize(FateCode)), - ?FORALL(InjectedBin, injection(Binary), - try Org = aeb_fate_code:deserialize(InjectedBin), - NewBin = aeb_fate_code:serialize(Org), - NewOrg = (catch aeb_fate_code:deserialize(NewBin)), - ?WHENFAIL(eqc:format("Deserialize ~p gives\n~p\nSerializes to ~p\n", [InjectedBin, Org, NewOrg]), - equals(NewBin, InjectedBin)) - catch _:_ -> - true - end))). + ?FORALL(FuzzedBin, fuzz(Binary), + try aeb_fate_code:deserialize(FuzzedBin) of + Code -> + ?WHENFAIL(eqc:format("Code:\n ~p\n", [Code]), + begin + Bin1 = aeb_fate_code:serialize(Code), + Code1 = aeb_fate_code:deserialize(Bin1), + ?WHENFAIL(eqc:format("Reserialized\n ~120p\n", [Bin1]), + equals(Code, Code1)) + end) + catch _:_ -> true + end))). prop_opcodes() -> ?FORALL(Opcode, choose(0, 16#ff), @@ -128,8 +131,8 @@ bblock(Failure, Ops) -> end end || Op <- Ops ]. -injection(Binary) -> - ?LET({N, Inj}, {choose(0, byte_size(Binary) - 1), choose(0,255)}, +fuzz(Binary) -> + ?LET({N, Inj}, {choose(0, byte_size(Binary) - 1), choose(0, 255)}, begin M = N * 8, <> = Binary, diff --git a/src/aeb_fate_generate_ops.erl b/src/aeb_fate_generate_ops.erl index 5adb95c..e656347 100644 --- a/src/aeb_fate_generate_ops.erl +++ b/src/aeb_fate_generate_ops.erl @@ -161,8 +161,8 @@ ops_defs() -> , { 'MAP_TO_LIST', 16#70, false, 3, [a,a], map_to_list, {map}, list, "Arg0 := The tuple list representation of the map Arg1."} , { 'STR_LENGTH', 16#71, false, 3, [a,a], str_length, {string}, integer, "Arg0 := The length of the string Arg1."} - , { 'ECVERIFY', 16#72, false, 1300, [a,a,a,a], ecverify, {hash, address, signature}, boolean, "Arg0 := ecverify(Hash, PubKey, Signature)"} - , { 'ECVERIFY_SECP256K1', 16#73, false, 1300, [a,a,a,a], ecverify_secp256k1, {hash, signature, signature}, boolean, "Arg0 := ecverify_secp256k1(Hash, PubKey, Signature)"} + , { 'ECVERIFY', 16#72, false, 1300, [a,a,a,a], ecverify, {bytes, address, bytes}, boolean, "Arg0 := ecverify(Hash, PubKey, Signature)"} + , { 'ECVERIFY_SECP256K1', 16#73, false, 1300, [a,a,a,a], ecverify_secp256k1, {bytes, bytes, bytes}, boolean, "Arg0 := ecverify_secp256k1(Hash, PubKey, Signature)"} , { 'CONTRACT_TO_ADDRESS', 16#74, false, 3, [a,a], contract_to_address, {contract}, address, "Arg0 := Arg1 - A no-op type conversion"} , { 'AUTH_TX_HASH', 16#75, false, 3, [a], auth_tx_hash, {}, variant, "If in GA authentication context return Some(TxHash) otherwise None."}