package domain import ( "testing" "git.smesh.lol/tinywallet/pkg/wallet" ) // TestRestoredSeedFindsCoinsAtTheStandardAccount: the blake wallet derives new addresses from // account 1, but a seed restored from any other wallet has its coins at account 0. A sync that // searched only its own account would report "no coins" for a funded wallet, which is the one lie // a restore must never tell. func TestRestoredSeedFindsCoinsAtTheStandardAccount(t *testing.T) { const phrase = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" blakeProfile, err := wallet.ProfileFor("blake", "regtest") if err != nil { t.Fatal(err) } if blakeProfile.Account != wallet.AccountBlake { t.Fatalf("blake derives from account %d", blakeProfile.Account) } if blakeProfile.Account == wallet.AccountBTC { t.Fatal("this test is pointless if blake and btc use one account") } derived, err := derive(phrase, blakeProfile) if err != nil { t.Fatal(err) } if err != nil { t.Fatal(err) } standard, err := derived.ForAccount(wallet.AccountBTC) if err != nil { t.Fatal(err) } coin, err := standard.Address(false, 3) if err != nil { t.Fatal(err) } meta := Meta{Account: blakeProfile.Account, Receive: 4} scripts, err := scriptsFor(derived, meta, 10, nil) if err != nil { t.Fatal(err) } found := false for _, script := range scripts { if string(script) == string(coin.Script()) { found = true } } if !found { t.Fatal("the standard account's address is not searched, so its coins would be invisible") } // The spend path must know that script too, or the coin can be found but never signed. keys, err := (&Domain{}).spendKeys(derived, meta) if err != nil { t.Fatal(err) } key, ok := keys[string(coin.Script())] if !ok { t.Fatal("the standard account's script has no spend key") } if key.account != wallet.AccountBTC { t.Fatalf("spend key is for account %d", key.account) } }