solitude.testing module¶
-
solitude.testing.
SOL_new
(cfg: Union[dict, str] = 'solitude.yaml', relative_to: Optional[str] = None) → solitude.testing.context.TestingContext[source]¶ Create a new testing context
Parameters: - cfg – configuration dictionary or path. If cfg is a string, it is interpreted as a path to the yaml or json file containing the configuration dictionary.
- relative_to – a path, or None; if cfg is a path and relative_to is not None, make the path of the configuration file cfg relative to the parent directory of relative_to. This can be used with __file__ to make the configuration file location relative to the test script.
-
solitude.testing.
SOL
¶ alias of
solitude.testing.context.TestingContext
-
class
solitude.testing.
TestingContext
(cfg: dict)[source]¶ Bases:
object
-
__init__
(cfg: dict)[source]¶ Create a testing context containing configured instances of the client, server and compiler.
Contracts from Project.ObjectDir (if not null) are added to the client’s collection.
A server is started if Testing.RunServer is true. In this case, the client is connected to the new server endpoint address, whatever it is, overriding the client endpoint configuration.
Parameters: cfg – configuration dictionary
-
account
(address)¶ Enter a context which uses a specific account to perform all transactions in the context.
Parameters: address – address of the account to use Returns: an account context Contexts can be nested. In this case, the account in the last context will be used.
with client.account(client.address(0)): client.deploy("ContractName", args=())
-
address
(account_id: int)¶ Get the address of an account in the ETH node
Parameters: account_id – index of the account in the ETH node Returns: address of the account
-
capture
(pattern)¶ Enter a context which captures events emitted by transactions.
Parameters: pattern – a glob pattern string, or a regex object, to match the event name Returns: a capture context The event name is in the format:
{unitname}:{contractname}.{eventname}
All emitted events that match are stored within the client and can be accessed with
client.get_events()
. They are cleared before every capture.Nested captures will filter events that match any of the patterns in the context.
with client.capture("*:MyToken.Transfer"): my_token_instance.transfer(address, 13) assert client.get_events()[0].args[2] == 13 with client.capture(re.compile(r".*:MyToken\.Transfer")): my_token_instance.transfer(address, 1) assert client.get_events()[0].args[2] == 1
-
cfg
¶ Configuration
-
clear_events
() → None¶ Clear events generated within the last capture context
-
client
¶ Client instance
-
compiler
¶ Compiler instance
-
deploy
(contract_selector: str, args=(), wrapper=<class 'solitude.client.contract.ContractBase'>)¶ Deploy a contract
Parameters: - contract_selector – contract selector string,
see
solitude.common.ContractObjectList.select()
. The contract must be present in the compiler’s collection and must contain ABI and bytecode. - args – constructor arguments
- wrapper – wrapper class for contract (see ContractBase)
- contract_selector – contract selector string,
see
-
get_accounts
(reload=False) → list¶ Get the accounts stored in the ETH node
Parameters: reload – whether to refresh the account list by querying the node Retrurn: list of accounts
-
get_current_account
()¶ Get the account which is currently in use
Returns: address of the account in use
-
get_events
() → List[solitude.client.eth_client.EventLog]¶ Get events generated within the last capture context
Returns: list of event logs
-
get_last_blocktime
() → int¶ Get timestamp of last mined block
Returns: last block’s timestamp (in seconds)
-
increase_blocktime_offset
(seconds: int) → int¶ Increase the offset to apply to block.timestamp for newly mined blocks
Parameters: seconds – number of seconds to add to block.timestamp offset (in seconds) Returns: new block.timestamp offset (in seconds)
-
mine_block
() → None¶ Ask the ETH node to mine a new block
-
server
¶ Server instance
-