diff --git a/solution/.taq/development-state.json b/solution/.taq/development-state.json index 742e047..7e1949c 100644 --- a/solution/.taq/development-state.json +++ b/solution/.taq/development-state.json @@ -12,54 +12,59 @@ } ] }, - "@taqueria/plugin-ligo.test.1691396856682": { - "task": "test", + "@taqueria/plugin-ligo.compile.1691764048195": { + "task": "compile", "plugin": "@taqueria/plugin-ligo", - "time": 1691396856682, + "time": 1691764048195, "output": [ { - "contract": "unit_pokeGame.jsligo", - "testResults": "\"Sender 1 has balance : \"\n3800000000000mutez\n\"contract deployed with values : \"\nKT1CWLhYPpX17qpCyLgTPKxijHwAkbqvF89H(None)\nSuccess (1298n)\n{feedback = \"kiss\" ; pokeTraces = [tz1hkMbkLPkvhxyqsQoBoLPqb1mruSzZx3zy -> {feedback = \"\" ; receiver = KT1CWLhYPpX17qpCyLgTPKxijHwAkbqvF89H}]}\nEverything at the top-level was executed.\n- testSender1Poke exited with value ().\n\nšŸŽ‰ All tests passed šŸŽ‰" - } - ] - }, - "@taqueria/plugin-ligo.test.1691397097944": { - "task": "test", - "plugin": "@taqueria/plugin-ligo", - "time": 1691397097944, - "output": [ + "contract": "proxy.jsligo", + "artifact": "artifacts/proxy.tz" + }, { - "contract": "mutation_pokeGame.jsligo", - "testResults": "Some tests failed :(" + "contract": "proxy.storageList.jsligo", + "artifact": "artifacts/proxy.default_storage.tz\n" + }, + { + "contract": "proxy.parameterList.jsligo", + "artifact": "" } ] }, - "@taqueria/plugin-ligo.test.1691397133161": { - "task": "test", + "@taqueria/plugin-ligo.compile.1691764068045": { + "task": "compile", "plugin": "@taqueria/plugin-ligo", - "time": 1691397133161, + "time": 1691764068045, "output": [ { - "contract": "mutation_pokeGame.jsligo", - "testResults": "\"Sender 1 has balance : \"\n3800000000000mutez\n\"contract deployed with values : \"\nKT1USnxrNkXwdetJQJ18uNgWJtaMDY4gdzPd(None)\nSuccess (1330n)\n{feedback = \"kiss\" ; pokeTraces = [tz1hkMbkLPkvhxyqsQoBoLPqb1mruSzZx3zy -> {feedback = \"\" ; receiver = KT1USnxrNkXwdetJQJ18uNgWJtaMDY4gdzPd}]}\n\"Sender 1 has balance : \"\n3800000000000mutez\nEverything at the top-level was executed.\n- test_mutation exited with value ().\n\nšŸŽ‰ All tests passed šŸŽ‰" + "contract": "pokeGameLambda.jsligo", + "artifact": "artifacts/pokeGameLambda.tz" } ] }, - "@taqueria/plugin-ligo.test.1691399461929": { - "task": "test", + "@taqueria/plugin-ligo.compile.1691764160054": { + "task": "compile", "plugin": "@taqueria/plugin-ligo", - "time": 1691399461929, + "time": 1691764160054, "output": [ { - "contract": "unit_pokeGame.jsligo", - "testResults": "\"Sender 1 has balance : \"\n3800000000000mutez\n\"*** Run test to pass ***\"\n\"contract deployed with values : \"\nKT1BKUzj4fKj9yD3U5w4HcCwSBum28pELgfi(None)\nSuccess (1860n)\n\"*** Check initial ticket is here ***\"\n{feedback = \"kiss\" ; pokeTraces = [] ; ticketOwnership = [tz1hkMbkLPkvhxyqsQoBoLPqb1mruSzZx3zy -> (KT1BKUzj4fKj9yD3U5w4HcCwSBum28pELgfi , (\"can_poke\" , 1n))]}\nSuccess (1024n)\n{feedback = \"kiss\" ; pokeTraces = [tz1hkMbkLPkvhxyqsQoBoLPqb1mruSzZx3zy -> {feedback = \"\" ; receiver = KT1BKUzj4fKj9yD3U5w4HcCwSBum28pELgfi}] ; ticketOwnership = []}\n\"*** Run test to fail ***\"\n\"contract deployed with values : \"\nKT1TvWVCW7y9jEWaEoBq6b5UHDY6PVrQ9ifQ(None)\nSuccess (1401n)\n\"*** Check initial ticket is here ***\"\n{feedback = \"kiss\" ; pokeTraces = [] ; ticketOwnership = []}\nFail (Rejected ((\"User does not have tickets => not allowed\" , KT1TvWVCW7y9jEWaEoBq6b5UHDY6PVrQ9ifQ)))\n{feedback = \"kiss\" ; pokeTraces = [] ; ticketOwnership = []}\nEverything at the top-level was executed.\n- testSender1Poke exited with value ().\n- testSender1PokeWithNoTicketsToFail exited with value ().\n\nšŸŽ‰ All tests passed šŸŽ‰" + "contract": "pokeGameLambda.jsligo", + "artifact": "artifacts/pokeGameLambda.tz" + }, + { + "contract": "pokeGameLambda.storageList.jsligo", + "artifact": "No storage expressions found\n" + }, + { + "contract": "pokeGameLambda.parameterList.jsligo", + "artifact": "No parameter expressions found\n" } ] }, - "@taqueria/plugin-ligo.compile.1691417387724": { + "@taqueria/plugin-ligo.compile.1693837601857": { "task": "compile", "plugin": "@taqueria/plugin-ligo", - "time": 1691417387725, + "time": 1693837601857, "output": [ { "contract": "pokeGame.jsligo", @@ -75,10 +80,10 @@ } ] }, - "@taqueria/plugin-ligo.compile.1691417744480": { + "@taqueria/plugin-ligo.compile.1693837613825": { "task": "compile", "plugin": "@taqueria/plugin-ligo", - "time": 1691417744480, + "time": 1693837613825, "output": [ { "contract": "proxy.jsligo", @@ -94,52 +99,58 @@ } ] }, - "@taqueria/plugin-ligo.compile.1691764048195": { - "task": "compile", + "@taqueria/plugin-ligo.test.1693840595479": { + "task": "test", "plugin": "@taqueria/plugin-ligo", - "time": 1691764048195, + "time": 1693840595479, "output": [ { - "contract": "proxy.jsligo", - "artifact": "artifacts/proxy.tz" - }, - { - "contract": "proxy.storageList.jsligo", - "artifact": "artifacts/proxy.default_storage.tz\n" - }, - { - "contract": "proxy.parameterList.jsligo", - "artifact": "" + "contract": "unit_pokeGame.jsligo", + "testResults": "Some tests failed :(" } ] }, - "@taqueria/plugin-ligo.compile.1691764068045": { - "task": "compile", + "@taqueria/plugin-ligo.test.1693840607049": { + "task": "test", "plugin": "@taqueria/plugin-ligo", - "time": 1691764068045, + "time": 1693840607049, "output": [ { - "contract": "pokeGameLambda.jsligo", - "artifact": "artifacts/pokeGameLambda.tz" + "contract": "unit_pokeGame.jsligo", + "testResults": "Some tests failed :(" } ] }, - "@taqueria/plugin-ligo.compile.1691764160054": { - "task": "compile", + "@taqueria/plugin-ligo.test.1693840649257": { + "task": "test", "plugin": "@taqueria/plugin-ligo", - "time": 1691764160054, + "time": 1693840649257, "output": [ { - "contract": "pokeGameLambda.jsligo", - "artifact": "artifacts/pokeGameLambda.tz" - }, + "contract": "unit_pokeGame.jsligo", + "testResults": "Some tests failed :(" + } + ] + }, + "@taqueria/plugin-ligo.test.1693840690077": { + "task": "test", + "plugin": "@taqueria/plugin-ligo", + "time": 1693840690077, + "output": [ { - "contract": "pokeGameLambda.storageList.jsligo", - "artifact": "No storage expressions found\n" - }, + "contract": "unit_pokeGame.jsligo", + "testResults": "Some tests failed :(" + } + ] + }, + "@taqueria/plugin-ligo.test.1693841086075": { + "task": "test", + "plugin": "@taqueria/plugin-ligo", + "time": 1693841086075, + "output": [ { - "contract": "pokeGameLambda.parameterList.jsligo", - "artifact": "No parameter expressions found\n" + "contract": "unit_pokeGame.jsligo", + "testResults": "\"Sender 1 has balance : \"\n3800000000000mutez\nSuccess (2807n)\n{entrypoints = [\"changeVersion\" -> {addr = KT1HWpsJxenWT6m1Rjr71iQR5DXr5ffUYyEh ; method = \"changeVersion\"} ; \"Init\" -> {addr = KT1HWpsJxenWT6m1Rjr71iQR5DXr5ffUYyEh ; method = \"Init\"} ; \"feedback\" -> {addr = KT1HWpsJxenWT6m1Rjr71iQR5DXr5ffUYyEh ; method = \"feedback\"} ; \"Poke\" -> {addr = KT1HWpsJxenWT6m1Rjr71iQR5DXr5ffUYyEh ; method = \"Poke\"} ; \"PokeAndGetFeedback\" -> {addr = KT1HWpsJxenWT6m1Rjr71iQR5DXr5ffUYyEh ; method = \"PokeAndGetFeedback\"}] ; governance = tz1MBWU1WkszFfkEER2pgn4ATKXE9ng7x1sR}\n\"calling _testPokeGame on proxy : \"\nKT1UE3DgZCk9HK7GMQ9yTMDS6vkwheN2dX3a(None)\nSuccess (1359n)\n\"calling _testPokeGame on proxy : \"\nKT1UE3DgZCk9HK7GMQ9yTMDS6vkwheN2dX3a(None)\nSuccess (1357n)\n{feedback = \"kiss\" ; pokeTraces = [tz1hkMbkLPkvhxyqsQoBoLPqb1mruSzZx3zy -> {feedback = \"\" ; receiver = KT1HWpsJxenWT6m1Rjr71iQR5DXr5ffUYyEh}] ; ticketOwnership = [] ; tzip18 = {contractNext = None (()) ; contractPrevious = None (()) ; proxy = KT1UE3DgZCk9HK7GMQ9yTMDS6vkwheN2dX3a ; version = 1n}}\nEverything at the top-level was executed.\n- testSender1Poke exited with value ().\n\nšŸŽ‰ All tests passed šŸŽ‰" } ] } diff --git a/solution/.taq/state.json b/solution/.taq/state.json index f41e760..fec0995 100644 --- a/solution/.taq/state.json +++ b/solution/.taq/state.json @@ -1,6 +1,6 @@ // WARNING: This file is autogenerated and should NOT be modified { - "build": "6a57340", + "build": "72f27cf", "configHash": "f2656a55015d2ecada534d41983a72fd2b6c2498405360dc60ec1c1bbbc169e7", "tasks": { "ligo": { diff --git a/solution/contracts/.ligo/repository_id b/solution/contracts/.ligo/repository_id new file mode 100644 index 0000000..46d7438 --- /dev/null +++ b/solution/contracts/.ligo/repository_id @@ -0,0 +1 @@ +93de71ba-4efe-481e-2438-5678fc53dd32 \ No newline at end of file diff --git a/solution/contracts/proxy.jsligo b/solution/contracts/proxy.jsligo index 36f7b22..35293b9 100644 --- a/solution/contracts/proxy.jsligo +++ b/solution/contracts/proxy.jsligo @@ -21,7 +21,11 @@ type changeVersion = { type storage = { governance: address, //admins - entrypoints: big_map //interface schema map + entrypoints: big_map< + string, + entrypointType + > //interface schema map + }; type _return = [list, storage]; diff --git a/solution/contracts/proxy.storageList.jsligo b/solution/contracts/proxy.storageList.jsligo index 1eb00fd..9a88117 100644 --- a/solution/contracts/proxy.storageList.jsligo +++ b/solution/contracts/proxy.storageList.jsligo @@ -3,5 +3,9 @@ const default_storage = { governance: "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb" as address, //admins entrypoints: Big_map.empty as - big_map //interface schema map + big_map< + string, + entrypointType + > //interface schema map + }; diff --git a/solution/contracts/unit_pokeGame.jsligo b/solution/contracts/unit_pokeGame.jsligo new file mode 100644 index 0000000..1bf01b1 --- /dev/null +++ b/solution/contracts/unit_pokeGame.jsligo @@ -0,0 +1,172 @@ +#import "./pokeGame.jsligo" "PokeGame" +#import "./proxy.jsligo" "Proxy" +// reset state + +const _ = Test.reset_state(2 as nat, list([]) as list); + +const admin = Test.nth_bootstrap_account(0); + +const sender1: address = Test.nth_bootstrap_account(1); + +const _ = Test.log("Sender 1 has balance : "); + +const _ = Test.log(Test.get_balance(sender1)); + +const _ = Test.set_baker(admin); + +const _ = Test.set_source(admin); + +const initial_tez = 0 as tez; + +//functions + +export const _testPokeGame = ( + taddr: typed_address, + entrypoint: string, + payload: bytes, + s: address +): unit => { + const contr = Test.to_contract(taddr); + const contrAddress = Tezos.address(contr); + const _ = Test.log("calling _testPokeGame on proxy : "); + const _ = Test.log(contr); + Test.set_source(s); + const status = + Test.transfer_to_contract( + contr, + CallContract({ entrypointName: entrypoint, payload: payload }), + 0 as tez + ); + Test.log(status) +}; + +//********** TESTS *************/ + +const testSender1Poke = + ( + (): unit => { + /***PROXY **/ + + const _ = Test.set_source(admin); + const proxy_initial_storage = + { + governance: admin, //admins + entrypoints: Big_map.empty as + big_map< + string, + Proxy.entrypointType + > //interface schema map + + }; + const [tProxyaddr, _, _] = + Test.originate_module( + contract_of (Proxy), + proxy_initial_storage, + initial_tez + ); + const proxyContr = Test.to_contract(tProxyaddr); + const proxyContrAddress = Tezos.address(proxyContr); + /***CONTRACT **/ + + const _ = Test.set_source(admin); + const initial_storage = + { + pokeTraces: Map.empty as map, + feedback: "kiss", + ticketOwnership: Map.empty as map>, //ticket of claims + tzip18: { + proxy: proxyContrAddress, + version: 1 as nat, + contractPrevious: None() as option
, + contractNext: None() as option
+ } + }; + const [addr, _, _] = + Test.originate_from_file( + "./pokeGame.jsligo", + "main", + list([]), + Test.eval(initial_storage), + initial_tez + ); + /**Upgrade proxy **/ + + const status = + Test.transfer_to_contract( + proxyContr, + Upgrade( + [ + list( + [ + { + name: "Poke", + isRemoved: false, + entrypoint: Some({ method: "Poke", addr: addr }) + }, + { + name: "PokeAndGetFeedback", + isRemoved: false, + entrypoint: Some( + { method: "PokeAndGetFeedback", addr: addr } + ) + }, + { + name: "Init", + isRemoved: false, + entrypoint: Some({ method: "Init", addr: addr }) + }, + { + name: "changeVersion", + isRemoved: false, + entrypoint: Some({ method: "changeVersion", addr: addr }) + }, + { + name: "feedback", + isRemoved: false, + entrypoint: Some({ method: "feedback", addr: addr }) + } + ] + ) as list, + None() as option + ] + ), + 0 as tez + ); + Test.log(status); + const storeProxy: Proxy.storage = Test.get_storage(tProxyaddr); + Test.log(storeProxy); + /** RUN TEST*/ + + _testPokeGame( + tProxyaddr, + "Init", + Bytes.pack([sender1, 10 as nat]), + sender1 + ); + _testPokeGame(tProxyaddr, "Poke", (bytes `dummy`), sender1); + const taddr = + Test.cast_address(addr) as + typed_address; + const store: PokeGame.storage = Test.get_storage(taddr); + Test.log(store); + //check poke is registered + + match( + Map.find_opt(sender1, store.pokeTraces), + { + Some: (pokeMessage: PokeGame.pokeMessage) => { + assert_with_error( + pokeMessage.feedback == "", + "feedback " + pokeMessage.feedback + " is not equal to expected " + + "(empty)" + ); + assert_with_error( + pokeMessage.receiver == addr, + "receiver is not equal" + ) + }, + None: () => assert_with_error(false, "don't find traces") + } + ) + } + )();