Skip to content

Tests check sequence verify - #1793

Open
talelbaz wants to merge 12 commits into
kaspanet:v0.11.1-devfrom
talelbaz:testsCheckSequenceVerify
Open

talelbaz wants to merge 12 commits into
kaspanet:v0.11.1-devfrom
talelbaz:testsCheckSequenceVerify

Conversation

@talelbaz

Copy link
Copy Markdown
Contributor

The second part of #1257
Tests for CSV (conditioned by time and DAA score).

@talelbaz talelbaz self-assigned this Jul 12, 2021
@codecov

codecov Bot commented Jul 12, 2021

Copy link
Copy Markdown

Codecov Report

Merging #1793 (7ade8bb) into v0.11.0-dev (2ae1b78) will increase coverage by 3.29%.
The diff coverage is 71.89%.

❗ Current head 7ade8bb differs from pull request most recent head 881d857. Consider uploading reports for the commit 881d857 to get more accurate results
Impacted file tree graph

@@               Coverage Diff               @@
##           v0.11.0-dev    #1793      +/-   ##
===============================================
+ Coverage        58.71%   62.00%   +3.29%     
===============================================
  Files              582      596      +14     
  Lines            22924    26766    +3842     
===============================================
+ Hits             13459    16596    +3137     
- Misses            7318     7924     +606     
- Partials          2147     2246      +99     
Impacted Files Coverage Δ
app/rpc/rpchandlers/ban.go 0.00% <0.00%> (ø)
app/rpc/rpchandlers/unban.go 0.00% <0.00%> (ø)
cmd/kaspactl/main.go 0.00% <0.00%> (ø)
cmd/kaspawallet/daemon/client/client.go 0.00% <0.00%> (ø)
cmd/kaspawallet/daemon/server/broadcast.go 0.00% <0.00%> (ø)
domain/consensus/utils/txscript/engine.go 84.12% <ø> (-0.35%) ⬇️
domain/consensus/utils/txscript/error.go 92.30% <ø> (+3.41%) ⬆️
...nager/blocktemplatebuilder/blocktemplatebuilder.go 68.08% <0.00%> (+2.23%) ⬆️
infrastructure/config/config.go 12.10% <ø> (+0.99%) ⬆️
...twork/netadapter/standalone/minimal_net_adapter.go 0.00% <0.00%> (ø)
... and 659 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 28ac77b...881d857. Read the comment docs.

@svarogg svarogg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've only reviewed the first test properly, the rest of the tests have similar problems, so please fix all of them.

Also, please try to find as much common code between the tests and extract that into methods.

}
defer teardown(false)

blockAHash, _, err := testConsensus.AddBlock([]*externalapi.DomainHash{testConsensus.DAGParams().GenesisHash}, nil, nil)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add a comment explaining the structure of DAG you are building, and why

}
fees := uint64(1)
// Create a CSV script
numOfDAAScoreToWait := uint64(10)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please rename num -> number

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Alternatively, you can just rename to daaScoreToWait

@@ -0,0 +1,524 @@
package consensus_test

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The filename should be all_lower_case (same for timelock_cltv_test.go)

if err != nil {
t.Fatalf("Error creating blockE: %v", err)
}
// bit 62 of sequence defines if it's conditioned by DAA score(set to 0) or by time (set to 1).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These are implementation details that you are leaking outside where they are supposed to be.

To mitigate, do one of the following:

  1. Either convert sequenceTypeFlag to boolean.
  2. Or do some magic with constants.SequenceLockTimeIsSeconds. I don't have a concrete plan what to do, discuss with me if you prefer this path/

if err != nil {
t.Fatalf("Error creating transactionThatSpentTheLockedOutput: %v", err)
}
// Add a block that contains a transaction that spends the locked output before the time, and therefore should be failed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not failed, but rather - rejected

if err != nil {
t.Fatalf("The block should be valid since the output is not locked anymore. but got an error: %v", err)
}
validBlockStatus, err := testConsensus.BlockStatusStore().Get(testConsensus.DatabaseContext(), stagingArea,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's not valid yet. It's only expected to be valid.
Please rename to actualBlockStatus or just blockStatus

if err != nil {
t.Fatalf("Error creating blockA: %v", err)
}
blockBHash, _, err := testConsensus.AddBlock([]*externalapi.DomainHash{blockAHash}, nil, nil)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You are creating 4 blocks one after the other. Please use a loop

}

// TestRelativeTimeOnCheckSequenceVerify verifies that if the relative target is set to be X DAA score,
// and the absolute DAA score is X before having X DAA score more than the time the UTXO was mined, then the output will remain locked.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

and the absolute DAA score is

There's no such things as "the absolute DAA score", there's "the actual DAA score" or something similar.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also the rest of the sentance is really hard to understand, please revise (Talk to me if need someone to brainstorm with)

if err != nil {
return nil, err
}
stamp := uint64(lockedOutputBlock.Header.TimeInMilliseconds())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please rename to timestamp

testConsensus *testapi.TestConsensus) (*externalapi.DomainTransaction, error) {

var lockTime, sequence uint64
if sequenceTypeFlag == 1 { // Conditioned by time:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please take as much lines as possible out of the if

@stasatdaglabs
stasatdaglabs changed the base branch from v0.11.0-dev to v0.11.1-dev July 29, 2021 05:33
@D-Stacks

Copy link
Copy Markdown
Contributor

is this an important test, or why is it still in the PRs while being so old?

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.

3 participants