Update and fix quickcheck fuzz test

This commit is contained in:
Ulf Norell 2019-06-20 11:59:23 +02:00 committed by Hans Svensson
parent 33a1d5f4fb
commit f7f0dfde51
2 changed files with 17 additions and 14 deletions

View File

@ -51,14 +51,17 @@ prop_fail_serializes() ->
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
?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() ->
@ -128,7 +131,7 @@ bblock(Failure, Ops) ->
end
end || Op <- Ops ].
injection(Binary) ->
fuzz(Binary) ->
?LET({N, Inj}, {choose(0, byte_size(Binary) - 1), choose(0, 255)},
begin
M = N * 8,

View File

@ -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."}