package wallet import "testing" // TestNativeCoins: on a chain whose wallet signs the legacy message, a confirmed // coin at or below the fork is shared history and is not this chain's money. An // unconfirmed coin descends from coins the wallet was allowed to spend, so it // is native. A chain with no fork (the regtest rig's two chains) is all native. // // The XBT wallet is different: it signs SIGHASH_UNIFIED, which makes the spend // invalid on the other chain, so a pre-fork coin is safe to spend and Native // does not filter it. func TestNativeCoins(t *testing.T) { btc := Profile{Name: "btc"} if !btc.Native(0) || !btc.Native(800_000) { t.Fatal("a chain with no fork refused a coin") } legacy := Profile{Name: "btc", ForkHeight: 100} if !legacy.Native(0) { t.Fatal("an unconfirmed coin was called foreign") } for _, height := range []uint32{1, 50, 100} { if legacy.Native(height) { t.Fatalf("height %d is at or below the fork but was called native", height) } } for _, height := range []uint32{101, 1000} { if !legacy.Native(height) { t.Fatalf("height %d is after the fork but was called foreign", height) } } blake := Profile{Name: "blake", ForkHeight: 100} for _, height := range []uint32{0, 1, 100, 101} { if !blake.Native(height) { t.Fatalf("unified XBT height %d was called foreign", height) } } }