scenario.h3("Allowlisted from_ and to_") scenario += g.addToAllowlist(sp.record(address=alice.address)).run(sender=admin.address) scenario += g.addToAllowlist(sp.record(address=bob.address)).run(sender=admin.address) scenario += t.transfer(sp.record(to_=alice.address, from_=bob.address)).run(sender=bob.address) scenario.h3("Controller can move tokens") scenario += t.transfer(sp.record(to_=alice.address, from_=bob.address)).run(sender=admin.address) scenario.h3("Blocklisted to_") scenario += g.addToBlocklist(sp.record(address=alice.address)).run(sender=admin.address) scenario += t.transfer(sp.record(to_=alice.address, from_=bob.address)).run(sender=bob.address, valid=False) scenario.h3("Controller can't move tokens to a blocked address") scenario += t.transfer(sp.record(to_=alice.address, from_=bob.address)).run(sender=admin.address, valid=False) scenario.h3("Blocklisted from_") scenario += t.transfer(sp.record(to_=bob.address, from_=alice.address)).run(sender=alice.address, valid=False) scenario.h3("Controller can move tokens out of a blocked address") scenario += t.transfer(sp.record(to_=bob.address, from_=alice.address)).run(sender=admin.address) scenario.h3("Blocklisted to_") scenario += g.addToBlocklist(sp.record(address=bob.address)).run(sender=admin.address) scenario += t.transfer(sp.record(to_=alice.address, from_=bob.address)).run(sender=bob.address, valid=False) scenario.h3("Controller should not move tokens to a blocked address") scenario += t.transfer(sp.record(to_=alice.address, from_=bob.address)).run(sender=admin.address, valid=False) sp.add_compilation_target( "GeneralTransferManager_compiled", GeneralTransferManager( administrators = sp.set([sp.address("tz1f6KNARa6KykKhoxAugtKwohmEfz8jrvUH")]) ) )
scenario = sp.test_scenario() # GIVEN a reserve contract reserve = FarmRewardReserve() scenario += reserve # WHEN the governor is rotated scenario += reserve.setGovernorContract( Addresses.ROTATED_ADDRESS).run(sender=Addresses.GOVERNOR_ADDRESS) # THEN the address is rotated scenario.verify( reserve.data.governorAddress == Addresses.ROTATED_ADDRESS) @sp.add_test(name="setGovernorContract - fails if not called by governor") def test(): scenario = sp.test_scenario() # GIVEN a reserve contract reserve = FarmRewardReserve() scenario += reserve # WHEN the governor is rotated by someone other than the governor. # THEN the call fails. scenario += reserve.setGovernorContract(Addresses.ROTATED_ADDRESS).run( sender=Addresses.NULL_ADDRESS, valid=False, ) sp.add_compilation_target("farm-reward-reserve", FarmRewardReserve())
sp.for feeData in keyValueList: sp.if self.data.fees.contains(feeData.key): sp.if feeData.value.update_time > self.data.fees[feeData.key].update_time: self.data.fees[feeData.key] = feeData.value sp.else: self.data.fees[feeData.key] = feeData.value if "templates" not in __name__: @sp.add_test(name="Fee Store") def test(): admin = sp.test_account("Administrator") c1 = FeeStore(admin.address) scenario = sp.test_scenario() scenario.h1("Fee Store") scenario += c1 scenario += c1.update({"USDC": sp.record(approve=100000, initiateWait=100000, addCounterParty=100000, redeem=100000, update_time=sp.timestamp(1612864882))}).run(sender=sp.address("tz1-random"), valid=False) scenario += c1.update({"USDC": sp.record(approve=100000, initiateWait=100000, addCounterParty=100000, redeem=100000, update_time=sp.timestamp(1612864882))}).run(sender=admin) scenario += c1.update({"USDC": sp.record(approve=200000, initiateWait=100000, addCounterParty=100000, redeem=100000, update_time=sp.timestamp(1612864880))}).run(sender=admin) scenario.verify(c1.data.fees["USDC"].approve == 100000) scenario += c1.update_admin(sp.address("tz1-new-admin") ).run(sender=sp.address("tz1-random"), valid=False) scenario += c1.update_admin(sp.address("tz1-new-admin") ).run(sender=admin) scenario.verify(c1.data.admin == sp.address("tz1-new-admin")) sp.add_compilation_target("FeeStore", FeeStore(sp.address("tz1Y8UNsMSCXyDgma8Ya51eLx8Qu4AoLm8vt")), storage=None)
tvalue = sp.TInt, l = big_map_first ), big_map_second = sp.big_map( tkey = sp.TString, tvalue = sp.TString, l = big_map_second ) ) @sp.entry_point def add_first(self, params): self.data.big_map_first[params.key] = params.value @sp.entry_point def add_second(self, params): self.data.big_map_second[params.key] = params.value @sp.entry_point def always_fail(self, params): sp.set_type(params.amount, sp.TNat) sp.if params.amount >= 0: sp.failwith("I'm failing") inputs = list(map(lambda input: json.loads(input), sys.argv[1:])) sp.add_compilation_target("default", MyContract(*inputs))
scenario.h3("Admin removes a pair") scenario += swapContract.removeSwapPair(["xtz/usdtz"]).run(sender=admin) # only swap pairs available can be used scenario += swapContract.offer(_swapHash=swapHash, _value=2000000, _expected=1900000, _refundTimestamp=sp.timestamp(159682500), _pair="xtz/usdtz", _asset="xtz").run(sender=bob, amount=sp.utils.nat_to_mutez(3500000), now=sp.timestamp(159682400), valid=False) scenario.h3("Alice fails to set a delegate") voting_powers = { sp.key_hash("tz1YB12JHVHw9GbN66wyfakGYgdTBvokmXQk"): 0, } # only admin can set baker scenario += swapContract.setBaker(sp.some(sp.key_hash("tz1YB12JHVHw9GbN66wyfakGYgdTBvokmXQk"))).run(sender=alice,voting_powers = voting_powers, valid=False) scenario.h3("Admin sets a delegate") scenario += swapContract.setBaker(sp.some(sp.key_hash("tz1YB12JHVHw9GbN66wyfakGYgdTBvokmXQk"))).run(sender=admin,voting_powers = voting_powers) scenario.verify(swapContract.baker==sp.some(sp.key_hash("tz1YB12JHVHw9GbN66wyfakGYgdTBvokmXQk"))) scenario.h3("Alice fails to withdraw commission fees") # only admin can transfer service fees scenario += swapContract.transferFees(bob.address).run(sender=alice, valid=False) scenario.h3("Update Baker") scenario += swapContract.transferFees(bob.address).run(sender=admin) scenario.verify(swapContract.balance == sp.tez(0)) scenario.h3("Transfer rights from Admin to Bob") scenario += swapContract.updateAdmin(bob.address).run(sender=admin) sp.add_compilation_target("TezosSwap", Swap(_admin=sp.address("tz1Y8UNsMSCXyDgma8Ya51eLx8Qu4AoLm8vt"), _swapFee=15, _commission=0), storage=None)
tvalue=Harbinger.OracleDataType ) ).run(sender=defaultOracleContractAddress) scenario.h2("THEN the asset with two valid updates computes a VWAP based on two updates.") asset1PartialVWAP1 = Harbinger.computeVWAP( high=asset1High1, low=asset1Low1, close=asset1Close1, volume=asset1Volume1 ) asset1PartialVWAP2 = Harbinger.computeVWAP( high=asset1High2, low=asset1Low2, close=asset1Close2, volume=asset1Volume2 ) asset1Expected = (asset1PartialVWAP1 + asset1PartialVWAP2) // (asset1Volume1 + asset1Volume2) scenario.verify(contract.data.assetMap[assetCode1].computedPrice == asset1Expected) scenario.h2("AND the asset with one valid update computes a VWAP based only on the first update.") asset1Expected = Harbinger.computeVWAP( high=asset2High1, low=asset2Low1, close=asset2Close1, volume=asset2Volume1 ) // asset2Volume1 scenario.verify(contract.data.assetMap[assetCode2].computedPrice == asset1Expected) sp.add_compilation_target("normalizer", NormalizerContract())
# Then things go as planned and the value in the box is updated scenario.verify(box.data.value == newValue) # Of course, if we try to update the box directly, that fails. scenario += box.update(sp.nat(4)).run( sender=multisigAddress, valid=False, ) # Oh no, the DAO is unstable. Let's break glass to get back control scenario += breakGlass.breakGlass(multisigAddress).run( sender=multisigAddress) # THEN the permissions are updated scenario.verify(box.data.governorAddress == multisigAddress) # AND the multisig can update the value. multisigValue = sp.nat(5) scenario += box.update(multisigValue).run(sender=multisigAddress, ) scenario.verify(box.data.value == multisigValue) # And the DAO has no perms. scenario += breakGlass.runLambda(updateLambda).run( sender=daoAddress, valid=False, ) sp.add_compilation_target("liquidity-pool-break-glass", LiquidityPoolBreakGlass())
# This specific main uses the relative new feature of non-default tests # sp.for the browser version. if "templates" not in __name__: add_test(environment_config()) # if not global_parameter("only_environment_test", False): # add_test(FA12_config(debug_mode=True), is_default=not sp.in_browser) # add_test(FA12_config(readable=False), is_default=not sp.in_browser) # add_test(FA12_config(force_layouts=False), is_default=not sp.in_browser) # add_test(FA12_config(lazy_entry_points=True), is_default=not sp.in_browser) # add_test( # FA12_config(lazy_entry_points_multiple=True), is_default=not sp.in_browser # ) sp.add_compilation_target( "ST12_compiled", ST12( config = environment_config(), administrators = sp.set([sp.address("tz1M9CMEtsXm3QxA7FmMU2Qh7xzsuGXVbcDr")]), validators = sp.set([sp.address("KT1QkFxZqfCok6LZUJ7zDn6gCDBS7kSao26P")]), burners = sp.set([sp.address("KT1S3M3Cn7XBLcNi54cfvMP15j9ew4W4eb1C")]), minters = sp.set([sp.address("KT1S3M3Cn7XBLcNi54cfvMP15j9ew4W4eb1C")]), metadata = sp.big_map(l = { "": sp.bytes_of_string("tezos-storage:m"), "m" : sp.bytes_of_string("{\"name\":\"Test\",\"version\":\"security token v1.0\",\"description\":\"Test Digital Security Token\"}"), "name" : sp.bytes_of_string("Test"), "symbol" : sp.bytes_of_string("TST"), "decimals" : sp.bytes_of_string("18"), }) ) )
import smartpy as sp class Migrations(sp.Contract): def __init__(self, owner): self.init(owner=owner, last_completed_migration="") def setCompleted(self, completed): sp.verify(sp.sender == self.data.owner) self.data.last_completed_migration = completed if "templates" not in __name__: sp.add_compilation_target("Migrations_compiled", Migrations(sp.address("tz1")))
sp.record( schedule_name = "8 Months Cliff Vesting From 12-12-2020", from_ = bob.address, to_ = alice.address ) ]) ).run(sender = admin) scenario += v.changeBeneficieryForAll( sp.list([ sp.record( from_ = alice.address, to_ = bob.address ) ]) ).run(sender = alice, valid = False) scenario += v.changeBeneficieryForAll( sp.list([ sp.record( from_ = alice.address, to_ = bob.address ) ]) ).run(sender = admin) if "templates" not in __name__: add_test() sp.add_compilation_target("VestingEscrowWallet_compiled", VestingEscrowMinterBurnerWallet())
# Tests @sp.add_test(name="Welcome") def test(): # We define a test scenario, together with some outputs and checks scenario = sp.test_scenario() # We first define a contract and add it to the scenario c1 = MyContract(12, 123) scenario += c1 # And call some of its entry points scenario += c1.myEntryPoint(12) scenario += c1.myEntryPoint(13) scenario += c1.myEntryPoint(14) scenario += c1.myEntryPoint(50) scenario += c1.myEntryPoint(50) scenario += c1.myEntryPoint(50).run( valid=False) # this is expected to fail # Finally, we check its final storage scenario.verify(c1.data.myParameter1 == 151) # We can define another contract using the current state of c1 c2 = MyContract(1, c1.data.myParameter1) scenario += c2 scenario.verify(c2.data.myParameter2 == 151) sp.add_compilation_target("demo", MyContract(12, 123))
scenario += view_totalSupply c1.getTotalSupply((sp.unit, view_totalSupply.typed.target)) scenario.verify_equal(view_totalSupply.data.last, sp.some(17000000)) scenario.h2("Allowance") view_allowance = Viewer(sp.TNat) scenario += view_allowance c1.getAllowance((sp.record(owner = alice.address, spender = bob.address), view_allowance.typed.target)) scenario.verify_equal(view_allowance.data.last, sp.some(1000000)) sp.add_compilation_target( "FA1_2", FA12( admin = sp.address("tz1e4Lv5uAUyN3qGFpsNp94vu4yNFCzK9mwX"), config = FA12_config( support_upgradable_metadata = True, use_token_metadata_offchain_view = True ), token_metadata = { "decimals" : "6", # Mandatory by the spec "name" : "Oropocket Gold", # Recommended "symbol" : "XTZGold", # Recommended # Extra fields "thumbnailUri" : 'https://oropocket.com/unifarm/assets/icons/oro-gold.png' }, contract_metadata = { "" : "ipfs://QmYA6osSz1pzy3YviBV4WQvs8W4L7zCNedVXL3UsiapSsP", } ) )
scenario += view_totalSupply c1.getTotalSupply((sp.unit, view_totalSupply.typed.target)) scenario.verify_equal(view_totalSupply.data.last, sp.some(17000000)) scenario.h2("Allowance") view_allowance = Viewer(sp.TNat) scenario += view_allowance c1.getAllowance((sp.record(owner = alice.address, spender = bob.address), view_allowance.typed.target)) scenario.verify_equal(view_allowance.data.last, sp.some(1000000)) sp.add_compilation_target( "FA1_2", FA12( admin = sp.address("tz1e4Lv5uAUyN3qGFpsNp94vu4yNFCzK9mwX"), config = FA12_config( support_upgradable_metadata = True, use_token_metadata_offchain_view = True ), token_metadata = { "decimals" : "6", # Mandatory by the spec "name" : "Oropocket Silver", # Recommended "symbol" : "XTZSilver", # Recommended # Extra fields "thumbnailUri" : 'https://oropocket.com/unifarm/assets/icons/oro-silver.png' }, contract_metadata = { "" : "ipfs://QmYuu9tMdjty8FWie37yFrncA7oZC3MQwVhcddZpipvr4a", } ) )
scenario.verify(c2.data.ledger[c2.ledger_key.make(c1.address, 0)].balance == sp.nat(0)) scenario.verify(c2.data.ledger[c2.ledger_key.make(bob.address, 0)].balance == sp.nat(5)) # successful swap creation with same hash after redeem scenario += c1.initiateWait(_hashedSecret=hashSecret, initiator_eth_addr=init_eth, _refundTimestamp=sp.timestamp( 159682500), _amount=5).run(sender=alice, now=sp.timestamp(159682400)) # balance check scenario.verify(c2.data.ledger[c2.ledger_key.make(c1.address, 0)].balance == sp.nat(5)) scenario.verify(c2.data.ledger[c2.ledger_key.make(alice.address, 0)].balance== sp.nat(8)) # cannot be refunded before the refundtime scenario += c1.refund(hashSecret).run(sender=bob, now=sp.timestamp(159682450), valid=False) scenario += c1.refund(hashSecret).run(sender=alice, now=sp.timestamp(159682450), valid=False) # can be refunded in any initated or waiting state if refund time has come, can be done by anyone but funds transfered only to initiator scenario += c1.refund(hashSecret).run(sender=bob, now=sp.timestamp(159682550)) # cannot be refunded again once it has been refunded scenario += c1.refund(hashSecret).run(sender=alice, now=sp.timestamp(159682550), valid=False) # balance check scenario.verify(c2.data.ledger[c2.ledger_key.make(c1.address, 0)].balance == sp.nat(0)) scenario.verify(c2.data.ledger[c2.ledger_key.make(alice.address, 0)].balance == sp.nat(13)) sp.add_compilation_target("FA2Swap", FA2Swap(_admin=sp.address("tz1Y8UNsMSCXyDgma8Ya51eLx8Qu4AoLm8vt"), _fa2=sp.address("KT1Y8UNsMSCXyDgma8Ya51eLx8Qu4AoLm8vt"), _tokenID=0), storage=None)
valid=False, ) # Oh no, the DAO is unstable. Let's break glass to get back control newContractsParam = sp.record( governorContract=multisigAddress, tokenContract=meaninglessAddress, ovenProxyContract=meaninglessAddress, stabilityFundContract=meaninglessAddress, developerFundContract=meaninglessAddress, ) scenario += breakGlass.breakGlass(newContractsParam).run( sender=multisigAddress) # THEN the permissions are updated scenario.verify(box.data.governorAddress == multisigAddress) # AND the multisig can update the value. multisigValue = sp.nat(5) scenario += box.update(multisigValue).run(sender=multisigAddress, ) scenario.verify(box.data.value == multisigValue) # And the DAO has no perms. scenario += breakGlass.runLambda(updateLambda).run( sender=daoAddress, valid=False, ) sp.add_compilation_target("minter-break-glass", MinterBreakGlass())
scenario += view_totalSupply c1.getTotalSupply((sp.unit, view_totalSupply.typed.target)) scenario.verify_equal(view_totalSupply.data.last, sp.some(17)) scenario.h2("Allowance") view_allowance = Viewer(sp.TNat) scenario += view_allowance c1.getAllowance((sp.record(owner = alice.address, spender = bob.address), view_allowance.typed.target)) scenario.verify_equal(view_allowance.data.last, sp.some(1)) sp.add_compilation_target( "FA1_2", FA12( admin = sp.address("tz1M9CMEtsXm3QxA7FmMU2Qh7xzsuGXVbcDr"), config = FA12_config( support_upgradable_metadata = True, use_token_metadata_offchain_view = True ), token_metadata = { "decimals" : "18", # Mandatory by the spec "name" : "My Great Token", # Recommended "symbol" : "MGT", # Recommended # Extra fields "icon" : 'https://smartpy.io/static/img/logo-only.svg' }, contract_metadata = { "" : "ipfs://QmaiAUj1FFNGYTu8rLBjc3eeN9cSKwaF8EGMBNDmhzPNFd", } ) )
) ## ## Standard “main” ## ## This specific main uses the relative new feature of non-default tests ## for the browser version. if "templates" not in __name__: add_test(environment_config()) if not global_parameter("only_environment_test", False): add_test(FA2_config(debug_mode = True), is_default = not sp.in_browser) add_test(FA2_config(single_asset = True), is_default = not sp.in_browser) add_test(FA2_config(non_fungible = True, add_mutez_transfer = True), is_default = not sp.in_browser) add_test(FA2_config(readable = False), is_default = not sp.in_browser) add_test(FA2_config(force_layouts = False), is_default = not sp.in_browser) add_test(FA2_config(debug_mode = True, support_operator = False), is_default = not sp.in_browser) add_test(FA2_config(assume_consecutive_token_ids = False) , is_default = not sp.in_browser) add_test(FA2_config(store_total_supply = True) , is_default = not sp.in_browser) add_test(FA2_config(add_mutez_transfer = True) , is_default = not sp.in_browser) add_test(FA2_config(lazy_entry_points = True) , is_default = not sp.in_browser) sp.add_compilation_target("FA2_comp", FA2(config = environment_config(), metadata = sp.utils.metadata_of_url("https://example.com"), admin = sp.address("tz1M9CMEtsXm3QxA7FmMU2Qh7xzsuGXVbcDr")))
# Then things go as planned and the value in the box is updated scenario.verify(box.data.value == newValue) # Of course, if we try to update the box directly, that fails. scenario += box.update(sp.nat(4)).run( sender=multisigAddress, valid=False, ) # Oh no, the DAO is unstable. Let's break glass to get back control scenario += breakGlass.breakGlass(multisigAddress).run( sender=multisigAddress) # THEN the permissions are updated scenario.verify(box.data.governorAddress == multisigAddress) # AND the multisig can update the value. multisigValue = sp.nat(5) scenario += box.update(multisigValue).run(sender=multisigAddress, ) scenario.verify(box.data.value == multisigValue) # And the DAO has no perms. scenario += breakGlass.runLambda(updateLambda).run( sender=daoAddress, valid=False, ) sp.add_compilation_target("break-glass", BreakGlass())
amount=sp.tez(2), now=sp.timestamp(159682400)) # balance check scenario.verify(c1.balance == sp.tez(2)) # cannot be refunded before the refundtime scenario += c1.refund(hashSecret).run(sender=bob, now=sp.timestamp(159682450), valid=False) scenario += c1.refund(hashSecret).run(sender=alice, now=sp.timestamp(159682450), valid=False) # can be refunded in any initated or waiting state if refund time has come, can be done by anyone but funds transfered only to initiator scenario += c1.refund(hashSecret).run(sender=bob, now=sp.timestamp(159682550)) # cannot be refunded again once it has been refunded scenario += c1.refund(hashSecret).run(sender=alice, now=sp.timestamp(159682550), valid=False) # balance check scenario.verify(c1.balance == sp.tez(0)) sp.add_compilation_target( "AtomicSwap", AtomicSwap(sp.address("tz1Y8UNsMSCXyDgma8Ya51eLx8Qu4AoLm8vt")), storage=None)
scenario.verify(c2.data.balances[c1.address].balance == sp.nat(0)) scenario.verify(c2.data.balances[bob.address].balance == sp.nat(5)) # successful swap creation with same hash after redeem scenario += c1.initiateWait(_hashedSecret=hashSecret, initiator_eth_addr=init_eth, _refundTimestamp=sp.timestamp( 159682500), _amount=5).run(sender=alice, now=sp.timestamp(159682400)) # balance check scenario.verify(c2.data.balances[c1.address].balance == sp.nat(5)) scenario.verify(c2.data.balances[alice.address].balance == sp.nat(8)) # cannot be refunded before the refundtime scenario += c1.refund(hashSecret).run(sender=bob, now=sp.timestamp(159682450), valid=False) scenario += c1.refund(hashSecret).run(sender=alice, now=sp.timestamp(159682450), valid=False) # can be refunded in any initated or waiting state if refund time has come, can be done by anyone but funds transfered only to initiator scenario += c1.refund(hashSecret).run(sender=bob, now=sp.timestamp(159682550)) # cannot be refunded again once it has been refunded scenario += c1.refund(hashSecret).run(sender=alice, now=sp.timestamp(159682550), valid=False) # balance check scenario.verify(c2.data.balances[c1.address].balance == sp.nat(0)) scenario.verify(c2.data.balances[alice.address].balance == sp.nat(13)) sp.add_compilation_target("TokenSwap", TokenSwap(_admin=sp.address("tz1Y8UNsMSCXyDgma8Ya51eLx8Qu4AoLm8vt"), _fa12=sp.address("KT1Y8UNsMSCXyDgma8Ya51eLx8Qu4AoLm8vt")), storage=None)
# publicKey = testAccountPublicKey, # initialData = sp.big_map( # l = { # assetCode: initialData # }, # tkey = sp.TString, # tvalue = TezosOracle.OracleDataType # ) # ) # scenario += oracle # scenario.h2("AND a normalizer contract.") # normalizer = Normalizer.NormalizerContract( # oracleContractAddress = oracle.address # ) # scenario += normalizer # scenario.h2("WHEN an update is pushed from the oracle to the normalizer") # contractHandle = sp.contract( # sp.TBigMap(sp.TString, TezosOracle.OracleDataType), # sp.to_address(sp.self), # entry_point = "update" # ).open_some() # scenario += oracle.push(contractHandle) # scenario.h2("THEN the normalizer contains the VWAP.") # expectedVWAP = TezosOracle.computeVWAP(high, low, close, volume) // volume # scenario.verify(normalizer.data.computedPrice == expectedVWAP) sp.add_compilation_target("oracle", OracleContract())
c1 = HENDao([sp.address("tz1owner1"), sp.address("tz1owner2")]) scenario = sp.test_scenario() scenario.h1("Test Deposits") scenario += c1 admin = sp.address("tz1owner1") user2 = sp.address("tz1owner2") hacker = sp.address("tz1hacker") c1.deposit().run(sender=admin, amount= sp.mutez(10)) scenario.verify(c1.data.equity[admin] == sp.mutez(10)) c1.deposit().run(sender=admin, amount= sp.mutez(5)) scenario.verify(c1.data.equity[admin] == sp.mutez(15)) c1.deposit().run(valid=False, sender=hacker, amount=sp.mutez(10)) @sp.add_test(name = "Test_Buy") def test(): c1 = HENDao([sp.address("tz1owner1"), sp.address("tz1owner2")]) scenario = sp.test_scenario() scenario.h1("Test Buy") scenario += c1 admin = sp.address("tz1owner1") user2 = sp.address("tz1owner2") scenario.h2("Buying disabled when locked") c1.vote_buy(swap_id=123).run(valid=False, sender=admin) scenario.h2("Buying enabled when unlocked") # TODO write this test # TODO Add the initial addresses here when deploying contract sp.add_compilation_target("henDao", HENDao([]))
self.data.storedValue = params.value @sp.entry_point def double(self): self.data.storedValue *= 2 @sp.entry_point def divide(self, params): sp.verify(params.divisor > 5) self.data.storedValue /= params.divisor if "templates" not in __name__: @sp.add_test(name="StoreValue") def test(): c1 = StoreValue(12) scenario = sp.test_scenario() scenario.h1("Store Value") scenario += c1 c1.replace(value=15) scenario.p("Some computation").show(c1.data.storedValue * 12) c1.replace(value=25) c1.double() c1.divide(divisor=2).run(valid=False) scenario.verify(c1.data.storedValue == 50) c1.divide(divisor=6) scenario.verify(c1.data.storedValue == 8) sp.add_compilation_target("storeValue", StoreValue(12))
scenario.verify(c1.data.totalSupply == 17) scenario.verify(c1.data.balances[alice.address].balance == 8) scenario.verify(c1.data.balances[bob.address].balance == 9) scenario.h1("Views") scenario.h2("Balance") view_balance = Viewer(sp.TNat) scenario += view_balance scenario += c1.getBalance((alice.address, view_balance.typed)) scenario.verify_equal(view_balance.data.last, sp.some(8)) scenario.h2("Administrator") view_administrator = Viewer(sp.TAddress) scenario += view_administrator scenario += c1.getAdministrator((sp.unit, view_administrator.typed)) scenario.verify_equal(view_administrator.data.last, sp.some(admin.address)) scenario.h2("Total Supply") view_totalSupply = Viewer(sp.TNat) scenario += view_totalSupply scenario += c1.getTotalSupply((sp.unit, view_totalSupply.typed)) scenario.verify_equal(view_totalSupply.data.last, sp.some(17)) scenario.h2("Allowance") view_allowance = Viewer(sp.TNat) scenario += view_allowance scenario += c1.getAllowance((sp.record(owner = alice.address, spender = bob.address), view_allowance.typed)) scenario.verify_equal(view_allowance.data.last, sp.some(1)) sp.add_compilation_target("FA1_2", FA12(admin = sp.address("tz1M9CMEtsXm3QxA7FmMU2Qh7xzsuGXVbcDr")))