-
Notifications
You must be signed in to change notification settings - Fork 79
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
core: migrate native contract API tests to neotest framework #2299
Conversation
} | ||
|
||
func TestBlockedAccounts(t *testing.T) { | ||
chain := newTestChain(t) | ||
account := util.Uint160{1, 2, 3} | ||
policyHash := chain.contracts.Policy.Metadata().Hash | ||
|
||
transferTokenFromMultisigAccount(t, chain, testchain.CommitteeScriptHash(), | ||
chain.contracts.GAS.Hash, 100_00000000) | ||
|
||
t.Run("isBlocked, internal method", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These checks can be moved too, I think. We're testing native
package here anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're testing internal method here and it uses dao to retrieve blocked accounts. Our native tests can't be dependant on dao.
467eb7d
to
ad60607
Compare
Depends on #2298, still in progress. |
1378691
to
d63828c
Compare
5502441
to
45f543a
Compare
Codecov Report
@@ Coverage Diff @@
## master #2299 +/- ##
==========================================
+ Coverage 84.01% 84.03% +0.02%
==========================================
Files 307 308 +1
Lines 29840 29913 +73
==========================================
+ Hits 25070 25138 +68
+ Misses 3350 3347 -3
- Partials 1420 1428 +8
Continue to review full report at Codecov.
|
45f543a
to
0f85b4e
Compare
newGAS := e.Chain.GetUtilityTokenBalance(voters[i].ScriptHash()) | ||
newGAS.Sub(newGAS, gasBalance[i]) | ||
// TODO: deal with unexported CalculateNEOHolderReward | ||
gasForHold, err := e.Chain.CalculateNEOHolderReward(voters[i].ScriptHash(), e.Chain.BlockHeight()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roman-khimov, I'm not sure how to deal with this part of test. Here we need to compare voter rewards (second part), but CalculateNEOHolderReward
is unexported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Check the value against non-voter (holder) account that holds NEO for the same number of blocks.
- Hardcode exact GAS values generated for the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that hardcoded value is good and maintainable, so let's go with the first suggestion. I added these reference accounts and comment on why do we need them. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's a test, it can expect some exact value given known conditions, but comparing to non-voter is more flexible, of course.
bc.getNodesByRole(t, true, noderoles.NeoFSAlphabet, bc.BlockHeight()+1, 1) | ||
}) | ||
} | ||
|
||
func TestDesignate_DesignateAsRole(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is aimed to test exported contract methods (not via transaction invocation). However, it can easily be converted to use neotest. So do we need to convert it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a counterpart for it that does on-chain invocations? We can have tests like this if for some reason testing them from on-chain call is inappropriate or not possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried to convert this tests to on-chain-based, but occurs that we need to check best designated index and it's not possible with on-chain invocations. So I think we'd better leave this test as is.
pkg/neotest/basic.go
Outdated
h, err := e.Chain.GetNativeContractScriptHash(name) | ||
require.NoError(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reuse e.NativeHash(t, name)
?
for i := 0; i < height-1; i++ { | ||
e.AddNewBlock(t) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use GenerateNewBlocks
from the first commit?
for i := 0; i < int(e.Chain.GetConfig().MaxTraceableBlocks); i++ { | ||
e.AddNewBlock(t) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
0f85b4e
to
40ad0ab
Compare
newGAS := e.Chain.GetUtilityTokenBalance(voters[i].ScriptHash()) | ||
newGAS.Sub(newGAS, gasBalance[i]) | ||
// TODO: deal with unexported CalculateNEOHolderReward | ||
gasForHold, err := e.Chain.CalculateNEOHolderReward(voters[i].ScriptHash(), e.Chain.BlockHeight()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Check the value against non-voter (holder) account that holds NEO for the same number of blocks.
- Hardcode exact GAS values generated for the tests.
40ad0ab
to
bd9fcda
Compare
Not yet ready for review, I need to rebase on master and carefully inspect the whole set of changes. |
Added several methods that are useful for testing.
GAS and NEO tokens are sent to validators account (not the committee's one). For single-node chain they are the same, but for four-nodes chain they are different. Thus, use validators multisig address to create new accounts and to deploy contracts. Also, allow to provide desired account balance while creating new account.
bd9fcda
to
4982a9f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I think this makes tests much more readable, for example notary contract test became shorter. It also proves testing framework viability, which is important. Still, we have some hairy parts also that can be improved in future.
Compiler forces notification parameters to match the one specified in manifest, and manifest of `test_contract.go` tells that `to` parameter type is hash160: ``` event 'Transfer' should have 'Hash160' as type of 1 parameter, got: ByteArray ```
4982a9f
to
ce5dfdb
Compare
Part of #1472.
Migration goes well, but some tests need to be adjusted, so test refactoring is being made along the way. Progress: