Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CU-86dtu8tcn - Add boa test constructor to the documentation #1265

Merged
merged 2 commits into from
Jun 19, 2024

Conversation

luc10921
Copy link
Contributor

No description provided.

@luc10921 luc10921 requested a review from meevee98 June 17, 2024 21:04
@luc10921 luc10921 self-assigned this Jun 17, 2024
@melanke
Copy link
Contributor

melanke commented Jun 17, 2024

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 91.201%. remained the same
when pulling c9d1693 on CU-86dtu8tcn
into 8c6f9ae on development.

Comment on lines 50 to 52
Install [boa-test-constructor](https://pypi.org/project/boa-test-constructor/) with pip. We use this extension to run an isolated
test environment for smart contracts with a neo-go node. When installing boa-test-constructor, [neo-mamba](https://dojo.coz.io/neo3/mamba/index.html)
will be installed too.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is worth mentioning that the packages can be installed directly when neo3-boa is installed by using pip install neo3-boa[test]

Comment on lines 62 to 63
Then, create functions to test the expected behavior of your smart contract. To invoke or test invoke your smart
contract, use the `call` method from `SmartContractTestCase`. The two positional parameters are the name of the method
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the user reading this documentation may not know the difference between invoke and test invoke, you can just write "To invoke your smart contract [...]" here

argument to set up the test environment.
Then, create functions to test the expected behavior of your smart contract. To invoke or test invoke your smart
contract, use the `call` method from `SmartContractTestCase`. The two positional parameters are the name of the method
you want to invoke and a list of its arguments. The keyword parameters are the return type, a list of signing accounts,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure that methodName, args and returnType are mandatory

To persist an invocation, use the `signing_accounts` parameter to pass a list of signing accounts when calling the
smart contract. If you don't pass it, then it will always be a test invoke. The `signers` parameter can be used
alongside the `signing_accounts` if you want to change the witness scope of the invocation, or by itself if you want to
test invoke but also define the signers of the transaction.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are not going to explain what signers and witnesses scopes are in this file, can you link the neo documentation related to signers here to guide the user if it wants more information?

Comment on lines 91 to 106
@classmethod
def setUpClass(cls) -> None:
super().setUpClass()
# you can name the account whatever you want, but the password needs to be "123"
cls.user1 = cls.node.wallet.account_new("123", "alice")
cls.genesis = cls.node.wallet.account_get_by_label("committee")

asyncio.run(cls.asyncSetupClass())

@classmethod
async def asyncSetupClass(cls) -> None:
# this `transfer` method already uses the correct amount of decimals for the token
await cls.transfer(GAS, cls.genesis.script_hash, cls.user1.script_hash, 100)

# the smart contract I'm deploying is hello_world_with_deploy.py from the "Neo Methods" https://dojo.coz.io/neo3/boa/getting-started.html#neo-methods
cls.contract_hash = await cls.deploy("./smart_contract.nef", cls.genesis)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these code snippets should be along the texts that explain what to do, the text by itself does not help much without code to look into
If the user if following the documentation I don't think its test is going to look like this as the text before it suggests, there is mention to initiating accounts, but is not explicit that in this tutorial we're setting a user test account.

Comment on lines 101 to 106
async def asyncSetupClass(cls) -> None:
# this `transfer` method already uses the correct amount of decimals for the token
await cls.transfer(GAS, cls.genesis.script_hash, cls.user1.script_hash, 100)

# the smart contract I'm deploying is hello_world_with_deploy.py from the "Neo Methods" https://dojo.coz.io/neo3/boa/getting-started.html#neo-methods
cls.contract_hash = await cls.deploy("./smart_contract.nef", cls.genesis)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth mentioning that the test case run on a local chain that is going to reset each time the tests are executed, that's why the contract needs to be deployed and the user balance needs to me initialized

def setUpClass(cls) -> None:
super().setUpClass()
# you can name the account whatever you want, but the password needs to be "123"
cls.user1 = cls.node.wallet.account_new("123", "alice")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for clarity sake, i think it's better to put the label first

Suggested change
cls.user1 = cls.node.wallet.account_new("123", "alice")
cls.user1 = cls.node.wallet.account_new(label="alice", password="123")

@classmethod
def setUpClass(cls) -> None:
super().setUpClass()
# you can name the account whatever you want, but the password needs to be "123"
Copy link
Contributor

@meevee98 meevee98 Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason that the password needs to be "123"? is it a boa-test-constructor issue?

Comment on lines 58 to 60
synchronous, so if you need to set up asynchronous tasks, you can create another async method and use it int the
`asyncio.run` method from `asyncio`. Common operations would be: creating accounts, deploying the smart contract,
selecting your "main" smart contract, and transferring GAS to the new accounts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is worth mentioning why the tests must be async:
the tests use a local chain to run the invocations and the communication with the chain is asynchronous, so anything that needs to interact with it (deploy, token transfers, vote, etc) must be awaited

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 91.201%. remained the same
when pulling 8177c9f on CU-86dtu8tcn
into 8c6f9ae on development.

@meevee98 meevee98 merged commit 9c903f9 into development Jun 19, 2024
4 checks passed
@meevee98 meevee98 deleted the CU-86dtu8tcn branch June 19, 2024 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants