def test():

        scenario = sp.test_scenario()

        # sp.test_account generates ED25519 key-pairs deterministically:
        admin = sp.test_account("Admin")
        
        alice = sp.test_account("Alice")
        bob   = sp.test_account("Bob")
        robert = sp.test_account("Robert")

        scenario.h1("Contract")

        oracle  = USDOracle(admin.address)
        scenario += oracle 
  
        options = Securities(sp.address("tz1XfbFQgxj1sSfe2YyJPba5ZQuKMcV4FXAX"),sp.address("KT1HsVdNMvy4uTeorCFJD2kPVGzHXhpzJZjV"),oracle.address)
        scenario += options
        
        scenario += oracle.feedData(price=230).run(sender=admin)

        scenario += options.ContractWriter(amount=1000000000).run(sender=alice)
        scenario += options.ContractWriter(amount=2000000000).run(sender=robert)

        scenario += oracle.changeSecurities(address=options.address).run(sender=admin)
        scenario += oracle.SecuritiesPurchase(xtz = 1000000, token = 1000000000 , duration = 1 , spender = bob.address, order = 1).run(sender = bob)
        scenario += oracle.feedData(price=200).run(sender=admin)

        scenario += oracle.SecuritiesExercise(owner = bob.address).run(sender = bob )
Beispiel #2
0
 def test():    
     # DAO Contract testing#
     
     scenario = sp.test_scenario()
     scenario.h1("Accounts")
     #scenarionew.show([newadmin, newalice, newbob])
     
     admin = sp.test_account("Administrator")
     alice = sp.test_account("Alice")
     bob   = sp.test_account("Robert")
     
     scenario.show([admin, alice, bob])
 
     
     daoContract = DAOContract(_Admin=admin.address, members=5, amt=10)
     fa12 = FA12(daoContract.address)
     scenario.show([daoContract.address])
     scenario.show([fa12.address])
     scenario +=daoContract
     
     #scenario.h1("Initialize")
     #scenario += daoContract.intialize(fa12.address).run(sender = admin)
     
     
     scenario.h2("AddRequest")
     scenario += daoContract.addrequest(amt=10).run(sender=alice)
def test():
    scenario = sp.test_scenario()
    
    admin = sp.address("tz1XP2AUZAaCbi1PCNQ7pEdMS1EEjL4p4YPY")
    
    mark = sp.test_account("Mark")
    elon = sp.test_account("Mars")
    alice = sp.test_account("alice")
    
    # (1) Initialize Cryptobot as `cryptobot` with non_fungible set to True.
    # (2) Add it to the scenario.
    cryptobot = Cryptobot(FA2.FA2_config(non_fungible = True), admin)
    scenario += cryptobot
    
    # Mint 1 token to mark with symbol - "CTB", amount - 1, token_id - 0 and extras - {"value": "First bot"}
    scenario += cryptobot.mint(address = mark.address, 
                            amount = 1,
                            symbol = 'CTB',
                            token_id = 5,
                            extras = { "value": "4th bot"}).run(sender = admin)
    # Mint 1 token to mark with symbol - "CTB", amount - 1, token_id - 1 and extras - {"value": "Second bot"}                           
    scenario += cryptobot.mint(address = elon.address,
                            amount = 1,
                            symbol = 'CTB',
                            token_id = 6,
                            extras = { "value": "Second bot" }).run(sender = admin)
    
    scenario += cryptobot.offer_bot_for_sale(token_id = 6, min_sale_price = sp.mutez(1000)).run(sender = elon)
    
    # scenario += cryptobot.bot_no_longer_for_sale(token_id = 6).run(sender = elon)
    scenario += cryptobot.enter_bid_for_bot(token_id = 6).run(sender = mark, amount = sp.mutez(10000000))
    scenario += cryptobot.enter_bid_for_bot(token_id = 6).run(sender = alice, amount = sp.mutez(12000000))
    scenario += cryptobot.widthdraw_bid_for_bot(token_id = 6).run(sender = alice)
    scenario += cryptobot.accept_bid_for_bot(token_id = 6, nft_amount = 1).run(sender = elon)
Beispiel #4
0
def test():
    scenario = sp.test_scenario()
    scenario.h1("ExchangeRateOracle Tests")

    admin = sp.test_account("Admin")
    scenario.show(admin)

    operatorA = sp.test_account("operatorA")
    scenario.show(operatorA)

    operatorB = sp.test_account("operatorB")
    scenario.show(operatorB)

    caller = sp.test_account("caller")
    scenario.show(caller)

    oracle = ExchangeRateOracle(admin.address)
    scenario.register(oracle)

    consumer = ExchangeRateConsumer(oracle.address)
    scenario.register(consumer)

    scenario += oracle.updateOperatorList(operators = sp.set([operatorA.address, operatorB.address])).run(sender = admin)
    scenario += oracle.registerFeed(currencyPair = "USDEUR", cost = sp.mutez(1000)).run(sender = admin)
    scenario += oracle.updateFeed(currencyPair = "USDEUR", value = sp.nat(92), precision = sp.nat(2), timestamp = sp.timestamp(0), source = "Trusted Source").run(sender = operatorA)

    scenario += consumer.sendQuery(currencyPair = "USDEUR").run(sender = caller, amount = sp.mutez(1000))
    scenario.verify(consumer.data.value == 92)
    scenario.verify(consumer.data.currencyPair == "USDEUR")
    def test():

        scenario = sp.test_scenario()
        scenario.h1("FA1.2 template - Fungible assets")

        
        # sp.test_account generates ED25519 key-pairs deterministically:
        admin = sp.address("tz1LAWQmxJcnK43vR9G8jsNTzR6b2unZ58NX")
        alice = sp.test_account("Alice")
        bob   = sp.test_account("Robert")

        # Let's display the accounts:
        scenario.h1("Accounts")
       

        scenario.h1("Contract")
        c1 = ALAToken(admin)

        scenario.h1("Entry points")
        scenario += c1
        scenario.h2("Admin mints a few coins")
        scenario += c1.mint(address = alice.address, value = 12).run(sender = alice,amount = sp.tez(12))
        scenario += c1.mint(address = bob.address, value = 3).run(sender = admin,amount=sp.tez(3))
        # scenario += c1.mint(address = alice.address, value = 3).run(sender = admin)
        scenario += c1.AddContract(alice.address).run(sender=admin)
        scenario += c1.UnlockToken(address=bob.address,amount=100).run(sender=alice)
        scenario += c1.LockToken(address=bob.address,amount=100).run(sender=alice)
        scenario += c1.withdrawToken(amount=120000).run(sender=alice)
Beispiel #6
0
def test():
    #Accounts
    alice = sp.test_account('Alice')
    bob = sp.test_account('Bob')
    john = sp.test_account('John')
    anshu = sp.test_account('Anshu')
    ronak = sp.test_account('Ronak')
    
    scenario = sp.test_scenario()
    c = SimpleLottery()
    scenario += c
    
    scenario.h1('Lottery Test')
    
    scenario += c.buyTicket(1).run(sender = alice, amount = sp.tez(1))
    scenario += c.buyTicket(1).run(sender = bob, amount = sp.tez(1))
    scenario += c.buyTicket(1).run(sender = john, amount = sp.tez(1))
    scenario += c.buyTicket(1).run(sender = ronak, amount = sp.tez(1))
    
    scenario.h3('Buy Multiple (Change)')
    scenario += c.buyTicket(3).run(sender = anshu, amount = sp.tez(3))
    
    scenario.h3('Final Contract Balance')
    
    scenario.show(c.balance)
Beispiel #7
0
def test():
    
    scenario = sp.test_scenario()
    scenario.h1("NFT Contract")

    
    admin = sp.test_account("Administrator")
    alice = sp.test_account("Alice")
    bob   = sp.test_account("Bob")
    robert = sp.test_account("Robert")
    dibs = sp.test_account("Dibyo")
    
    # Let's display the accounts:
    scenario.h2("Accounts")
    scenario.show([admin, alice, bob, robert,dibs])
    
    
    c1 = TezNFT("state","ST",admin.address)
    scenario += c1
    
    scenario.h2("Admin minting Tokens")
    scenario += c1.mintCertificate(token_id = "Kitty1", address = alice.address, name="Alice", score = 20).run(valid = True, sender = admin)
    scenario += c1.mintCertificate(token_id = "Kitty2", address = bob.address, name="Bob", score = 50).run(sender = admin)
    scenario += c1.mintCertificate(token_id = "Kitty3", address = bob.address, name="Bob", score = 20).run(sender = admin)
    scenario += c1.mintCertificate(token_id = "Kitty5", address = alice.address, name="Alice", score = 100).run(sender = admin)
    
    scenario += c1.burnCertificate(token_id = "Kitty2").run(valid= True, sender = admin)
Beispiel #8
0
def test():
    # We define a test scenario, together with some outputs and checks
    scenario = sp.test_scenario()
    scenario.h1("Freelantzer Test")

    # We first define a contract and add it to the scenario
    c1 = Freelantzer()
    scenario += c1

    lister = sp.test_account("Lister")
    applier = sp.test_account("Applier")
    applier2 = sp.test_account("Applier2")
    applier3 = sp.test_account("Applier3")

    scenario += c1.list_job(_job_id="1", _company="Company Name", _job_description="link",
                            _contact="+91-9999999999", _max_hires=1).run(source=lister, amount=sp.mutez(1000))
    scenario += c1.list_job(_job_id="1", _company="Company Name", _job_description="link",
                            _contact="+91-9999999999", _max_hires=1).run(source=lister, amount=sp.mutez(1000), valid=False)

    scenario += c1.apply_for_job(_job_id="1",
                                 _resume="resume link").run(source=applier)
    scenario += c1.apply_for_job(_job_id="1",
                                 _resume="resume link").run(source=applier)

    scenario += c1.hire(_job_id="1", _candidate=applier.address,
                        _offer_letter="letter").run(source=lister)

    scenario.verify(c1.balance == sp.mutez(1000))
    scenario += c1.submit(_job_id="1",
                          _candidate=applier.address).run(source=applier, valid=False)
    scenario += c1.submit(_job_id="1",
                          _candidate=applier.address).run(source=lister)
    scenario.verify(c1.balance == sp.mutez(0))

    scenario += c1.list_job(_job_id="1", _company="Company Name", _job_description="link",
                            _contact="+91-9999999999", _max_hires=2).run(source=lister, amount=sp.mutez(1000))
    scenario += c1.apply_for_job(_job_id="1",
                                 _resume="resume link").run(source=applier)
    scenario += c1.apply_for_job(_job_id="1",
                                 _resume="resume link").run(source=applier2)
    scenario += c1.apply_for_job(_job_id="1",
                                 _resume="resume link").run(source=applier3)

    scenario += c1.hire(_job_id="1", _candidate=applier.address,
                        _offer_letter="letter").run(source=lister)
    scenario += c1.hire(_job_id="1", _candidate=applier2.address,
                        _offer_letter="letter").run(source=lister)
    scenario += c1.hire(_job_id="1", _candidate=applier3.address,
                        _offer_letter="letter").run(source=lister, valid=False)

    scenario += c1.submit(_job_id="1",
                          _candidate=applier.address).run(source=lister)
    scenario += c1.submit(_job_id="1",
                          _candidate=applier3.address).run(source=lister, valid=False)
    scenario.verify(c1.balance == sp.mutez(500))

    scenario += c1.submit(_job_id="1",
                          _candidate=applier2.address).run(source=lister)

    scenario.verify(c1.balance == sp.mutez(0))
Beispiel #9
0
def test():
    
    scenario = sp.test_scenario()
    
    admin = sp.test_account("Administrator")
    alice = sp.test_account("Alice")
    bob   = sp.test_account("Bob")
    robert = sp.test_account("Robert")
    dibs = sp.test_account("Dibyo")
    
    # Let's display the accounts:
    scenario.h2("Accounts")
    scenario.show([admin, alice, bob, robert,dibs])
    
    
    c1 = DataTokenizer("state","ST",admin.address)
    scenario += c1
    
    scenario.h2("Admin minting Tokens")
    scenario += c1.mintDataToken(token_id = "Kitty1", address = alice.address).run(sender = admin)
    scenario += c1.mintDataToken(token_id = "Kitty2", address = bob.address).run(sender = admin)
    scenario += c1.mintDataToken(token_id = "Kitty3", address = bob.address).run(sender = admin)
    
    scenario += c1.burnDataToken(token_id = "Kitty4").run(valid= False, sender = admin)
    scenario += c1.transfer(token_id="Kitty2", to= robert.address).run(sender = bob)
    
    scenario += c1.approve(token_id = "Kitty2", approve_to=dibs.address).run(sender = robert)

    scenario += c1.transferFrom(f = robert.address, t= alice.address, token_id = "Kitty2").run(sender = dibs)
Beispiel #10
0
    def test():
        scenario = sp.test_scenario()
        scenario.h1("FishcakeBox")

        admin = sp.test_account("Administrator")
        user1 = sp.test_account("User 1")
        user2 = sp.test_account("User 2")
        user3 = sp.test_account("User 3")
        scenario.show([admin, user1, user2])

        token = Fishcake(admin.address)
        box = FishcakeBox(
            reward=5,
            token=token,
            tokenAddress=sp.address('KT1WVtyDPFzjMkdkihX22LR4y5ye9kGYxjvF'))

        scenario += token
        scenario += box

        scenario += token.mint(address=box.address,
                               amount=100000,
                               symbol='FISH',
                               token_id=0).run(sender=admin)

        scenario += box
        scenario += box.redeem().run(sender=user1)
        scenario += box.redeem().run(sender=user2)
        scenario += box.redeem().run(sender=user1, valid=False)
Beispiel #11
0
def test():
    # init test and create html output
    scenario = sp.test_scenario()
    scenario.h1("SmartPy Proxy Contract")

    # init test values
    owner = sp.test_account("owner")
    notOwner = sp.test_account("notOwner")
    oldContract = sp.test_account("old")
    newContract = sp.test_account("new")

    # init contract
    proxy = Proxy(oldContract.address, owner.address)
    scenario += proxy
    # sanity check
    scenario.verify(proxy.data.contract == oldContract.address)

    # test entrypoints
    scenario.h2("[ENTRYPOINT] setAddr")
    scenario.h3("[SUCCESS-setAddr]")
    scenario += proxy.setAddr(newAddr=newContract.address).run(sender=owner)
    scenario.verify(proxy.data.contract == newContract.address)

    scenario.h3("[FAILED-setAddr] Invalid permissions")
    scenario += proxy.setAddr(newAddr=oldContract.address).run(sender=notOwner,
                                                               valid=False)
Beispiel #12
0
def test():
    scenario = sp.test_scenario()
    
    admin = sp.test_account("Alice")
    alice = sp.test_account("Alice")
    bob   = sp.test_account("Robert")
    alex = sp.test_account("Alex")
    token = sp.address("KT1KtyJeL78tdHnzwCPE8M14WDb1zqsnLkjQ")

    oracle = XTZOracle(admin.address)
    scenario += oracle

    c1 =  PutOptions(admin.address,10,20,token,oracle.address)
    scenario += c1 

    scenario += oracle.feedData(price=400).run(sender=admin)
    scenario += oracle.feedData(price=600).run(sender=admin)

    
    
    scenario += oracle.feedStrike(one=320,two=360,three=400,four=440,five=480).run(sender=admin)
    scenario += oracle.GetputSeller(Options=1,Ratio=80,address=admin.address,expire=14).run(sender=admin)
    
    scenario += c1.RestartCycle().run(sender=admin,now=30)
    
    scenario += c1.putSeller(amount=50000).run(now=45,sender=alice,amount=sp.tez(100000))
    scenario += c1.putSeller(amount=10000).run(now=45,sender=alice)
    scenario += c1.putSeller(amount=10000).run(now=45,sender=alex)

    scenario += c1.putBuyer(Options=1,StrikePrice=100,expire=7).run(sender=bob)
    #scenario += oracle.getDataMint(address=alice.address,amount=10).run(sender=alice)
Beispiel #13
0
    def test():
        scenario = sp.test_scenario()
        scenario.h1("FA2 Contract Name: " + config.name)
        scenario.table_of_contents()
        # sp.test_account generates ED25519 key-pairs deterministically:
        admin = sp.test_account("Administrator")
        alice = sp.test_account("Alice")
        bob   = sp.test_account("Robert")
        # Let's display the accounts:
        scenario.h2("Accounts")
        scenario.show([admin, alice, bob])
        c1 = FA2(config, admin.address)
        scenario += c1
        if config.non_fungible:
            # TODO
            return
        scenario.h2("Initial Minting")
        scenario.p("The administrator mints 100 token-0's to Alice.")
        scenario += c1.mint(address = alice.address,
                            amount = 100,
                            symbol = 'TK0',
                            token_id = 0).run(sender = admin)


        scenario.h2("Create certificate")
        scenario += c1.create_certificate(months = 5).run(sender = bob, amount=sp.mutez(100000000))

        scenario.h2("redeem  certificate")
        scenario += c1.redeem_certificate(token_id = 1).run(sender = bob)
Beispiel #14
0
    def test():

        scenario = sp.test_scenario()
        scenario.h1("FA1.2 template - StableCoin")

        scenario.table_of_contents()

        # sp.test_account generates ED25519 key-pairs deterministically:
        admin = sp.test_account("Administrator")
        alice = sp.test_account("Alice")
        bob   = sp.test_account("Robert")

        # Let's display the accounts:
        scenario.h1("Accounts")
        scenario.show([admin, alice, bob])

        c1 = VaultOpener(
        sp.address("KT1HsVdNMvy4uTeorCFJD2kPVGzHXhpzJZjV"),
        sp.address("KT1LiKCNGz2NHvtUH6hhB9usqw8TfuAktusy"),
        sp.address("tz1XfbFQgxj1sSfe2YyJPba5ZQuKMcV4FXAX")
        )
        scenario += c1  

        scenario += c1.OpenVault().run(sender=alice,amount=sp.tez(1))


# vault Opener - KT1Q5SPEdRTdki5fVXS7UHikFmWA2ckd3KdA
Beispiel #15
0
def test():

    scenario = sp.test_scenario()
    
    admin = sp.address("tz1LAWQmxJcnK43vR9G8jsNTzR6b2unZ58NX")
    alice = sp.test_account("Alice")
    bob   = sp.test_account("Robert")
    alex = sp.test_account("Alex")

    c1 = ALAToken(admin)
    c2 = PutOptions(admin,100,120,c1.address)
    
    scenario += c1
    scenario += c2
    
    scenario += c1.AddContract(c2.address).run(sender=admin)
    scenario += c1.mint(address = alice.address, value = 2).run(sender = alice,amount = sp.tez(2))

    scenario += c2.putSeller(amount=50000).run(now=45,sender=alice,amount=sp.tez(100000))
    
    scenario += c1.mint(address = bob.address, value = 1).run(sender = bob,amount = sp.tez(1))

    scenario += c2.putBuyer(StrikePrice=400,Options=1,expire=14).run(now=50,sender=bob)
    scenario += c2.WithdrawPremium().run(sender=alice)
    # scenario += c2.ModifyPrice(price=300).run(sender=admin)
    # scenario += c2.ReleaseContract().run(sender=bob)
Beispiel #16
0
def test():
    alice = sp.test_account("Alice")
    bob   = sp.test_account("Robert")
    scenario = sp.test_scenario()
    scenario.h1("Atomic Swap")

    # Here, two AtomicSwap contracts are created. One with Alice as the owner
    # and Bob as the counterparty, and the second with the identities reversed.
    # They are both secured with the same hash secret, so if the secret gets
    # revealed, then both swaps can happen.
    hashSecret = sp.blake2b(sp.bytes("0x12345678aabb"))
    c1 = AtomicSwap(sp.mutez(12), sp.timestamp(50), hashSecret,
                    alice.address,
                    bob.address)
    c2 = AtomicSwap(sp.mutez(20), sp.timestamp(50), hashSecret,
                    bob.address,
                    alice.address)
    scenario.h1("c1")
    scenario += c1
    scenario += c1.knownSecret(secret = sp.bytes("0x12345678aa")).run(sender = bob, valid = False)
    scenario += c1.knownSecret(secret = sp.bytes("0x12345678aabb")).run(sender = bob)
    scenario.h1("c2")
    scenario += c2
    scenario.h2("C2.export()")
    scenario.p(c2.export())
Beispiel #17
0
def test1():
    scenario = sp.test_scenario()
    scenario.h1("Candidates")
    
    # Candidates
    addr1 = sp.address("tz1LhS2WFCinpwUTdUb991ocL2D9Uk6FJGJK")
    addr2 = sp.address("tz1a6SkBrxCywRHHsUKN3uQse7huiBNSGb5p")
    addr3 = sp.address("tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5")
    # Manager - can end the voting
    addr4 = sp.address("tz1SwKQDtW8H7xLAS9ag4nxXbsQP5Pejwr7z")
    # Voters
    addr5 = sp.address("tz1SwKQDtW8H7xLAS9ag4nxXbsQP5Pejwr7z")
    addr6 = sp.address("tz1YH2LE6p7Sj16vF6irfHX92QV45XAZYHnX")
    
    contract = Ballot("Design", addr4, [(addr1, "George"), (addr2, "Tim"), (addr3, "Gina")], [addr5, addr6], 2)
    contract.balance = sp.tez(9)
    
    scenario += contract
    
    # Votes succeed
    scenario += contract.vote(votes = {addr1: 2}).run(valid = True,sender = addr5)
    scenario += contract.vote(votes = {addr2: 1}).run(valid = True, sender = addr6)
    # Not enough votes - vote fails
    scenario += contract.vote(votes = {addr1: 1}).run(valid=False,sender = addr5)
    
    # Assert addr1 has 2 votes, addr2 has 1 vote
    scenario.verify(contract.data.ballot[addr1] == sp.record(candidateName = "George", numberOfVotes = 2))
    scenario.verify(contract.data.ballot[addr2] == sp.record(candidateName = "Tim", numberOfVotes = 1))    
    
    # Ending contract
    scenario += contract.end().run(valid = True, sender = addr4)

    # Testing logic for ending contract
    scenario.h1("End")
    
    voterAccount = sp.test_account("Voter")
    candidateAccount = sp.test_account("Canddidate")
    managerAccount = sp.test_account("Manager")
    
    contract = Ballot("End", managerAccount.address, [(candidateAccount.address, "Candidate")], [voterAccount.address], 10)
    
    scenario += contract
    
    # Vote for open voting succeeds
    scenario += contract.vote(votes = {candidateAccount.address: 1}).run(valid = True, sender = voterAccount)
    
    # Ending vote with voterAccount fails
    scenario += contract.end().run(valid = False, sender = voterAccount)
    
    # Ending vote with managerAccount succeeds
    scenario += contract.end().run(valid = True, sender = managerAccount)
    
    # Voting after ending fails
    scenario += contract.vote(votes = {candidateAccount.address: 1}).run(valid = False, sender = voterAccount)
    
    # Ending contract again fails
    scenario += contract.end().run(valid = False, sender = managerAccount)
Beispiel #18
0
def test():
    hashSecret = sp.blake2b(sp.bytes("0x12345678aabb"))
    alice = sp.test_account("Alice")
    bob   = sp.test_account("Robert")
    c1 = AtomicSwap(sp.mutez(12), sp.timestamp(50), hashSecret,
                    alice.address,
                    bob.address)
    scenario  = sp.test_scenario()
    scenario.h1("Atomic Swap")
    scenario += c1
Beispiel #19
0
def test():
    time = sp.timestamp(1571761674)
    # Create test scenario
    scenario = sp.test_scenario()

    scenario.table_of_contents()

    # sp.test_account generates ED25519 key-pairs deterministically:
    alice = sp.test_account("Alice")
    bob = sp.test_account("Robert")

    # Create HTML output for debugging
    scenario.h1("Dutch Auction")

    # Instantiate Auction contract
    auction = DutchAuction(alice.address)
    scenario += auction

    alice_wallet = NFTWallet(alice.address)
    bob_wallet = NFTWallet(bob.address)

    scenario += alice_wallet
    scenario += bob_wallet

    scenario.h2("Create NFT")

    token_metadata = sp.map({"name": sp.bytes_of_string("Nft1")})
    scenario += alice_wallet.createNft(token_metadata).run(sender=alice)

    scenario.h2("Configure and start auction")
    scenario += alice_wallet.configNftAuction(auction_address=auction.address,
                                              opening_price=100,
                                              reserve_price=10,
                                              start_time=time,
                                              round_time=1000,
                                              ticket_id=0).run(source=alice,
                                                               sender=alice,
                                                               now=time)
    scenario.verify(~alice_wallet.data.tickets.contains(0))
    time = time.add_seconds(1)
    scenario += auction.startAuction().run(sender=alice, now=time)

    time = time.add_seconds(6001)

    scenario += auction.dropPrice(90).run(sender=alice, now=time)

    scenario.h2("Bob buys")
    time = time.add_seconds(1)
    scenario += auction.buy(bob_wallet.address).run(sender=bob,
                                                    source=bob,
                                                    now=time,
                                                    amount=sp.mutez(90))
    scenario.verify(bob_wallet.data.tickets.contains(0))
    scenario.verify(~auction.data.ticket.is_some())
Beispiel #20
0
def test():
    scenario = sp.test_scenario()
    scenario.h1("TZButton - A social dApp experiment")
    scenario.table_of_contents()

    creator = sp.test_account("creator")
    alice = sp.test_account("Alice")
    bob = sp.test_account("Robert")
    dan = sp.test_account("Dan")

    scenario.h2("Accounts")
    scenario.show([creator, alice, bob, dan])
    tz_button_contract = TZButton()
    tz_button_contract.set_initial_balance(INITIAL_BALANCE)
    scenario += tz_button_contract
    
    viewer_contract = ViewConsumer()
    scenario += viewer_contract

    scenario.h2("Pay-In")
    scenario.p("Alice does not pay")
    scenario += tz_button_contract.default().run(sender=alice, valid=False)

    scenario.p("Alice pays too little")
    scenario += tz_button_contract.default().run(sender=alice, amount=sp.mutez(20000), valid=False)

    scenario.p("Alice pays too much")
    scenario += tz_button_contract.default().run(sender=alice, amount=sp.mutez(20001), valid=False)

    scenario.p("Alice pays correct amount")
    scenario += tz_button_contract.default().run(sender=alice, amount=sp.mutez(200000))

    scenario.p("Bob pays correct amount")
    scenario += tz_button_contract.default().run(sender=bob, amount=sp.mutez(200000), now=sp.timestamp(1))

    scenario.p("Alice pays correct amount after bob again")
    scenario += tz_button_contract.default().run(sender=alice, amount=sp.mutez(200000), now=sp.timestamp(2))

    scenario.h2("Withdraw")
    scenario.p("Leader tries to withdraw before countdown")
    scenario += tz_button_contract.withdraw().run(sender=alice, valid=False)

    scenario.p("Non-Leader tries to withdraw after countdown")
    scenario += tz_button_contract.withdraw().run(sender=bob, valid=False, now=sp.timestamp(60*60*24))

    scenario.p("Non-Leader tries to pays correct amount after countdown")
    scenario += tz_button_contract.default().run(sender=bob, amount=sp.mutez(200000), valid=False, now=sp.timestamp(60*60*24))

    scenario.p("Leader tries to pays correct amount after countdown")
    scenario += tz_button_contract.default().run(sender=alice, amount=sp.mutez(200000), valid=False, now=sp.timestamp(60*60*24))

    scenario.p("Leader tries to withdraw after countdown")
    scenario += tz_button_contract.withdraw().run(sender=alice, now=sp.timestamp(60*60*24))
Beispiel #21
0
    def test():
        scenario = sp.test_scenario()
        scenario.h1("Chainlink Oracles")

        scenario.table_of_contents()

        scenario.h2("Accounts")
        admin = sp.test_account("Administrator")
        
        bob = sp.address("tz1WdHqcAo7gjtFDPMgD6yN8pk1sq67MJRjH")
        
        oracle1 = sp.test_account("Oracle1")

        client1_admin = sp.test_account("Client1 admin")
        client2_admin = sp.test_account("Client2 admin")

        scenario.show([admin, oracle1, client1_admin, client2_admin])

        scenario.h2("Link Token")
        link_token = Link_token(FA2.FA2_config(single_asset = True), admin.address)
        scenario += link_token
        scenario += link_token.mint(address = admin.address,
                                    amount = 200,
                                    symbol = 'tzLINK',
                                    token_id = 0).run(sender = admin)

        scenario.h2("Token Faucet")
        faucet = TokenFaucet(admin.address, link_token, link_token.address, 10)
        scenario += faucet

        scenario.h2("Oracle")
        oracle = Oracle(oracle1.address, link_token)
        scenario += oracle

        scenario.h2("Client1")
        client1 = Client(link_token.address, oracle.address, sp.bytes("0x0001"), client1_admin.address)
        scenario += client1

        scenario.h2("Client2")
        client2 = Client(link_token.address, oracle.address, sp.bytes("0x0001"), client2_admin.address)
        scenario += client2

        scenario.h2("Tokens")
        scenario += link_token.transfer([sp.record(from_ = admin.address, txs = [sp.record(to_ = faucet.address, token_id = 0, amount = 100)])]).run(sender = admin)
        scenario += link_token.transfer([sp.record(from_ = admin.address, txs = [sp.record(to_ = oracle1.address, token_id = 0, amount = 1)])]).run(sender = admin)
        scenario += faucet.request_tokens(sp.set([client1.address, client2.address]))
        #scenario += link_token.transfer([sp.record(from_ = client1_admin.address, txs = [sp.record(to_ = client1.address, token_id = 0, amount = 10)])]).run(sender = client1_admin)

        scenario.h2("Client1 sends a request that gets fulfilled")
        scenario.h3("A request")
        scenario += client1.request_fortune(payment = 1, timeout = 10).run(sender = bob)
Beispiel #22
0
def test():

    scenario = sp.test_scenario()

    admin = sp.address("tz1hPnEdcKWrdeZEAQiGfmV6knHA5En1fCwQ")

    alice = sp.test_account("Alice")
    bob   = sp.test_account("Robert")
    alex = sp.test_account("Alex")

    oracle = XTZOracle(admin)
    scenario += oracle

    token = ALAToken(admin,oracle.address)
    scenario += token

    options = PutOptions(admin,10,20,token.address,oracle.address)
    scenario += options

    scenario += oracle.feedData(price=400).run(sender=admin)

    scenario += oracle.feedStrike(one=320,two=360,three=400,four=440,five=480).run(sender=admin)

    scenario += token.mint(address = alice.address, value = 12).run(sender = alice,amount = sp.tez(12))

    scenario += token.mint(address = alex.address, value = 5).run(sender = alex,amount = sp.tez(5))

    scenario += token.mint(address = bob.address, value = 5).run(sender = bob,amount = sp.tez(5))

    scenario += options.RestartCycle().run(sender=admin,now=30)

    scenario += token.AddContract(options.address).run(sender=admin)

    scenario += options.putSeller(amount=60000).run(now=45,sender=alice,amount=sp.tez(1))
    scenario += options.putSeller(amount=40000).run(now=45,sender=alex)

    scenario += options.putBuyer(Options=1,StrikePrice=100,expire=7).run(sender=bob)

    scenario += options.WithdrawPremium().run(sender=alex,now=100)
    scenario += options.WithdrawPremium().run(sender=alice,now=150)

    scenario += oracle.feedData(price=100).run(sender=admin)

    scenario += options.ReleaseContract().run(sender=bob)

    scenario += options.WithdrawToken().run(sender=alice,now=1987250)
    scenario += options.WithdrawToken().run(sender=alex,now=1987350)

    scenario += options.RestartCycle().run(sender=admin,now=2160030)
    
Beispiel #23
0
def test():
    scenario = sp.test_scenario()
    rightful_owner = sp.test_account("Alice")
    attacker = sp.test_account("Robert")
    c1 = TestCheckSignature(rightful_owner.public_key)

    scenario += c1
    # Let's build a successful call:
    #
    scenario.h2("Successful Call")
    first_message_packed = sp.pack(
        sp.record(o="Hello World", n="should work", c=0))
    sig_from_alice = sp.make_signature(secret_key=rightful_owner.secret_key,
                                       message=first_message_packed,
                                       message_format="Raw")
    scenario += c1.setCurrentValue(
        newValue="should work", userSignature=sig_from_alice).run(valid=True)
    #
    scenario.h2("Replay Attack")
    scenario.p(
        "Trying to reuse the same signature is blocked by the value of the counter."
    )
    scenario += c1.setCurrentValue(
        newValue="should work", userSignature=sig_from_alice).run(valid=False)
    #
    #
    scenario.h2("Signature From Wrong Secret Key")
    scenario.p("Signing the right thing from a different secret-key.")
    #
    #
    # Gives:
    second_message_packed = sp.pack(
        sp.record(o="should work", n="Hello again World", c=1))
    sig_from_bob = sp.make_signature(secret_key=attacker.secret_key,
                                     message=second_message_packed,
                                     message_format="Raw")
    scenario += c1.setCurrentValue(newValue="Hello again World",
                                   userSignature=sig_from_bob).run(valid=False)
    #
    scenario.h2("Second Successful Call")
    scenario.p(
        "Showing that the previous call failed <b>because</b> of the secret-key (signing same bytes)."
    )
    sig_from_alice = sp.make_signature(secret_key=rightful_owner.secret_key,
                                       message=second_message_packed,
                                       message_format="Raw")
    scenario += c1.setCurrentValue(
        newValue="Hello again World",
        userSignature=sig_from_alice).run(valid=True)
Beispiel #24
0
def test():
    alice = sp.test_account('Alice')
    bob = sp.test_account('Bob')
    owner = sp.test_account('Owner')
    c1 = Verification(owner_address=owner.address, init_counter=0)
    scenario = sp.test_scenario()
    scenario += c1
    c1.increment(value=5).run(sender=alice.address)
    c1.increment(value=12).run(sender=alice.address, valid=False)
    c1.increment(value=7).run(sender=alice.address, valid=False)
    c1.increment(value=8).run(sender=bob.address)
    c1.decrement(value=2).run(sender=bob.address, valid=False)
    c1.decrement(value=3).run(sender=owner.address)
    c1.reset().run(sender=bob.address, valid=False)
    c1.reset().run(sender=owner.address)
 def __init__(self):
     self.init(
         guest = sp.test_account("VOID").address, 
         host = sp.test_account("VOID").address,
         nuki = sp.test_account("VOID").address,
         rent = sp.tez(0), 
         g_deposit = sp.tez(0), 
         h_deposit = sp.tez(0),
         active = False,         # G engaged/sent deposit
         in_house = False,       # G in house
         grace_ended = False,    # No more complaints
         complaint = False,      # G complained
         refund = False,         # G accepted refund
         # contract_id = 0,
         cp = 0) 
 def Cancellation_Guest(self):
     sp.verify(self.data.guest == sp.sender)
     sp.verify(self.data.active == True)
     sp.verify(self.data.in_house == False)
     sp.if (self.data.host == sp.test_account("VOID").address): 
         sp.send(self.data.guest, self.data.g_deposit)
         sp.send(self.data.guest, self.data.rent)
 def Guest_Leaves_Contract(self):
     sp.verify(sp.sender == self.data.guest)
     sp.verify(self.data.active == True)
     sp.verify(self.data.in_house == True)
     self.data.guest = sp.test_account("VOID").address
     self.data.in_house = False
     self.data.active = False
Beispiel #28
0
    def test():

        acc = sp.test_account(2)
        c1 = Wuwei(acc.address, '0x')

        scenario = sp.test_scenario()
        scenario.h1("Wuwei Deployment")
        scenario += c1
        scenario.h1("Round inputs")
        scenario += c1.prices_input(
            OBJ={
                'CNY': 545,
                'BRL': 3131,
                'EUR': 242,
                'CAN': 5453,
                'INR': 42342,
                'JPY': 13123,
                'KRW': 4232,
                'RUB': 52554,
                'CHF': 242,
                'HKD': 423433,
                'SGD': 423,
                'AED': 4333,
                'QAR': 34
            })

        scenario.h1("Initialize Client")
        c2 = Client()
        scenario += c2
        scenario.h1("Request value from key")
        scenario += c2.request_key(kt=c1.address, key='BRL')
Beispiel #29
0
def testEscrow():
    html = sp.test_scenario()

    html.h1("Escrow Cont")
    seller = sp.test_account("seller")
    buyer = sp.test_account("buyer")

    myContract = Escrow()
    #set the seller and price
    html += myContract

    html += myContract.setSeller(price=1).run(sender=seller)
    #set the buyer
    html += myContract.setBuyer().run(sender=buyer, amount=sp.tez(2))
    # buyer confirms they received item
    html += myContract.confirmReceived().run(sender=buyer)
Beispiel #30
0
def test():
    scenario = sp.test_scenario()
    scenario.h1('Land Register')
    
    manager = sp.test_account('Manager')
    
    r1 = sp.test_account('Registrar 1')
    r2 = sp.test_account('Registrar 2')
    r3 = sp.test_account('Registrar 3')
    
    c = LandRegister(manager=manager.address, registrars=sp.set([r1.address, r2.address, r3.address]) )
    
    scenario += c
    
    scenario.h2("Add Registrar")
    
    r4 = sp.test_account('Registrar 4')
    
    scenario += c.add_registrar(registrar=r4.address).run(sender=manager)
    
    scenario.h2("Add Registrar with Wrong Manager")
    
    wrong = sp.test_account('Wrong Manager')
    
    r5 = sp.test_account('Registrar 5')
    
    scenario += c.add_registrar(registrar=r5.address).run(sender=wrong, valid=False)
    
    
    scenario.h2("Remove Registrar")

    scenario += c.remove_registrar(registrar=r1.address).run(sender=manager)
    
    scenario.h2("Remove Registrar with Wrong Manager")
    
    scenario += c.remove_registrar(registrar=r2.address).run(sender=wrong, valid=False)
    
    
    scenario.h2("Add Land")
    
    land_owner = sp.test_account('Land Owner')
    
    land = {
        'A': (1,2),
        'B': (3,2),
        'C': (4,3),
        'D': (5,4)
    }
    
    code = "ABCD"
    
    scenario += c.add_land(owner=land_owner.address, land=land, code=code).run(sender=r3)
    
    
    scenario.h2("Add Land with Wrong Registrar")
    
    scenario += c.add_land(owner=land_owner.address, land=land, code=code).run(sender=wrong, valid=False)