Post
Topic
Board Development & Technical Discussion
Re: Test vectors for address generation
by
pooya87
on 03/02/2021, 08:10:23 UTC
@pooya87 Right, so you understand why I am trying to look for test vectors that I can include and run against my code, yes?

I have already included BIP32 tests and they pass, but looking for more. Currently implementing BIP39 tests, but what other test vectors I must test against?
You should test parts that are YOUR code not the libraries you are using. For example your TestBIP32SpecTestVector is basically repeating the tests that your library already has (https://github.com/btcsuite/btcutil/blob/master/hdkeychain/extendedkey_test.go). If you don't trust the library to be correct then you shouldn't be using it in first place.
The tests you write should only test your own code. For example it should test the part where you split the path into its parts and then pass the resulting uint32 to the third party (library) code to derive the child.

If I were you I'll pull this part out and put it in a separate method that returns a uint32[]
https://github.com/ashfame/btcwallet/blob/e24bad6fa3482c796dc1c8a1e0d588a93a489d22/wallet.go#L226-L242
Then write extensive number of tests for that method like this:
Code:
m (case where path refers to the master itself)
m/ (same but it has an extra separator)
m/1 (path has one index)
m/1/2 (path has two indexes)
m/1H (the index is hardened)
m/1h (a lower case is used)
m/1' (a different indicator which is more common than 'h', you'll find a bug in your code after running this case)
m/1/2'/3/4'/5/6h/7H (a mixture)
You can also decide how they behave, the first 2 cases can return error or an empty array or the last one can be rejected because it is a mixture or be flexible and accept that too.

Now your GetNodeKeys needs a lot less tests and you trust that node.Derive(deriveIndex) method that is calling the third party code is behaving correctly. You can also verify that correct behavior by checking the source code of the third party code like I posted above.