native_test.go raw

   1  package wallet
   2  
   3  import "testing"
   4  
   5  // TestNativeCoins: on a chain whose wallet signs the legacy message, a confirmed
   6  // coin at or below the fork is shared history and is not this chain's money. An
   7  // unconfirmed coin descends from coins the wallet was allowed to spend, so it
   8  // is native. A chain with no fork (the regtest rig's two chains) is all native.
   9  //
  10  // The XBT wallet is different: it signs SIGHASH_UNIFIED, which makes the spend
  11  // invalid on the other chain, so a pre-fork coin is safe to spend and Native
  12  // does not filter it.
  13  func TestNativeCoins(t *testing.T) {
  14  	btc := Profile{Name: "btc"}
  15  
  16  	if !btc.Native(0) || !btc.Native(800_000) {
  17  		t.Fatal("a chain with no fork refused a coin")
  18  	}
  19  
  20  	legacy := Profile{Name: "btc", ForkHeight: 100}
  21  
  22  	if !legacy.Native(0) {
  23  		t.Fatal("an unconfirmed coin was called foreign")
  24  	}
  25  
  26  	for _, height := range []uint32{1, 50, 100} {
  27  		if legacy.Native(height) {
  28  			t.Fatalf("height %d is at or below the fork but was called native", height)
  29  		}
  30  	}
  31  
  32  	for _, height := range []uint32{101, 1000} {
  33  		if !legacy.Native(height) {
  34  			t.Fatalf("height %d is after the fork but was called foreign", height)
  35  		}
  36  	}
  37  
  38  	blake := Profile{Name: "blake", ForkHeight: 100}
  39  
  40  	for _, height := range []uint32{0, 1, 100, 101} {
  41  		if !blake.Native(height) {
  42  			t.Fatalf("unified XBT height %d was called foreign", height)
  43  		}
  44  	}
  45  }
  46