-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1337 from lightninglabs/tlv-refactor-fixes
proof+tapdb: refactor and fix TLV unknown odd types bug for backward compatibility
- Loading branch information
Showing
20 changed files
with
305 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package proof | ||
|
||
import ( | ||
"context" | ||
"encoding/hex" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/lightninglabs/taproot-assets/internal/test" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestBIPTestVectorsBackwardCompatible tests that the BIP test vectors are | ||
// passing against an older code base (this test file will be copied to an old | ||
// version of tapd together with the test vectors in the CI). | ||
func TestBIPTestVectorsBackwardCompatible(t *testing.T) { | ||
t.Parallel() | ||
|
||
for idx := range allTestVectorFiles { | ||
var ( | ||
fileName = allTestVectorFiles[idx] | ||
testVectors = &TestVectors{} | ||
) | ||
test.ParseTestVectors(t, fileName, &testVectors) | ||
t.Run(fileName, func(tt *testing.T) { | ||
tt.Parallel() | ||
|
||
runBIPTestVectorBackwardCompatible(tt, testVectors) | ||
}) | ||
} | ||
} | ||
|
||
// runBIPTestVectorBackwardCompatible runs the tests in a single BIP test vector | ||
// file. | ||
func runBIPTestVectorBackwardCompatible(t *testing.T, | ||
testVectors *TestVectors) { | ||
|
||
for _, validCase := range testVectors.ValidTestCases { | ||
validCase := validCase | ||
|
||
t.Run(validCase.Comment, func(tt *testing.T) { | ||
tt.Parallel() | ||
|
||
// We want to make sure that the proof can be decoded | ||
// from the hex string and that the decoded proof's meta | ||
// hash matches. | ||
decoded := &Proof{} | ||
err := decoded.Decode(hex.NewDecoder( | ||
strings.NewReader(validCase.Expected), | ||
)) | ||
require.NoError(tt, err) | ||
|
||
if decoded.MetaReveal != nil { | ||
metaHash := decoded.MetaReveal.MetaHash() | ||
require.Equal( | ||
tt, | ||
validCase.Proof.Asset.GenesisMetaHash, | ||
hex.EncodeToString(metaHash[:]), | ||
) | ||
} | ||
|
||
// We can't verify the full proof chain but at least we | ||
// can verify the inclusion/exclusion proofs. | ||
_, err = decoded.VerifyProofs() | ||
require.NoError(tt, err) | ||
|
||
// If there is a genesis reveal, we can validate the | ||
// full proof chain, as it's the first proof in the | ||
// chain. | ||
if decoded.GenesisReveal != nil { | ||
_, err = decoded.Verify( | ||
context.Background(), nil, | ||
MockHeaderVerifier, | ||
DefaultMerkleVerifier, | ||
MockGroupVerifier, MockChainLookup, | ||
) | ||
require.NoError(tt, err) | ||
} | ||
}) | ||
} | ||
|
||
for _, invalidCase := range testVectors.ErrorTestCases { | ||
invalidCase := invalidCase | ||
|
||
t.Run(invalidCase.Comment, func(tt *testing.T) { | ||
tt.Parallel() | ||
|
||
require.PanicsWithValue(tt, invalidCase.Error, func() { | ||
invalidCase.Proof.ToProof(tt) | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.