Testing framework: add support for mutation of modules
Motivation and Context
From discussion with Benjamin w.r.t. PokeGame, mutation of modules can be somewhat awkward, as modules are not first-class.
Description
In this MR we follow the same approach as for originate_from_file
and add custom mutators for contracts as modules.
Component
-
compiler -
website -
webide -
vscode-plugin -
debugger
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to not work as expected) -
Performance improvement (non-breaking change that improves performance) -
None (change with no changelog)
Changelog
New primitives for doing mutation testing on module/namespace contracts in Test
:
let originate_module_and_mutate : (contract: module_contract<'p, 's>, init: 's, balance: tez, (tester: (originated_address: typed_address<'p, 's>, code: michelson_contract, size: int) => 'b)) => option<['b, mutation]>
let originate_module_and_mutate_all : (contract: module_contract<'p, 's>, init: 's, balance: tez, (tester: (originated_address: typed_address<'p, 's>, code: michelson_contract, size: int) => 'b)) => list<['b, mutation]>
Example in JsLIGO
#import "./contract_under_test/module_adder.mligo" "Adder"
const _tester = (a : typed_address<parameter_of Adder, int>, _ : michelson_contract, _ : int) : unit => {
let c : contract<parameter_of Adder> = Test.to_contract(a);
/* Test 1 */
let _ = Test.transfer_to_contract_exn(c, Add(0), (0 as tez));
Test.assert(Test.get_storage(a) == 0);
/* Test 2 */
let _ = Test.transfer_to_contract_exn(c, Add(1), (0 as tez));
Test.assert(Test.get_storage(a) == 1);
};
const test = (() : unit => {
let l = Test.originate_module_and_mutate_all(contract_of(Adder), 0, (0 as tez), _tester);
Test.log(l);
})();
Example in CameLIGO
#import "./contract_under_test/module_adder.mligo" "Adder"
let _tester (a : (Adder parameter_of, int) typed_address) (_ : michelson_contract) (_ : int) : unit =
let c : (Adder parameter_of) contract = Test.to_contract a in
(* Test 1 *)
let _ = Test.transfer_to_contract_exn c (Add 0) 0tez in
let () = assert (Test.get_storage a = 0) in
()
let test =
Test.originate_module_and_mutate_all (contract_of Adder) 0 0tez _tester
Checklist:
-
Changes follow the existing coding style (use dune @fmt
to check). -
Tests for the changes have been added (for bug fixes / feature). -
Documentation has been updated. -
Changelog description has been added (if appropriate). -
Start titles under ## Changelog
section with #### (if appropriate). -
There is no image or uploaded file in changelog -
Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by E. Rivas