February 2019
Intermediate to advanced
450 pages
9h 59m
English
Both smart contracts that we test have no arguments in the constructor. But what if we write a smart contract that has arguments in the constructor? How do we test that?
Let's write a simple smart contract that has arguments in the constructor. Name it contracts/Greeter2.vy:
greeting: bytes[20]@publicdef __init__(greeting_param: bytes[20]): self.greeting = greeting_param@publicdef setGreeting(x: bytes[20]): self.greeting = x@publicdef greet() -> bytes[20]: return self.greeting
Then, write the following test. Name it tests/test_greeter2.py:
import pytest@pytest.fixture()def greeter2_contract(chain): Greeter2Factory = chain.provider.get_contract_factory('Greeter2') deploy_txn_hash = Greeter2Factory.constructor(b'Hola').transact() ...Read now
Unlock full access