decred.org/dcrdex@v1.0.5/client/asset/eth/fundingcoin_test.go (about)

     1  // This code is available on the terms of the project LICENSE.md file,
     2  // also available online at https://blueoakcouncil.org/license/1.0.0.
     3  
     4  package eth
     5  
     6  import (
     7  	"bytes"
     8  	"testing"
     9  
    10  	"decred.org/dcrdex/dex/encode"
    11  )
    12  
    13  func TestFundingCoinID(t *testing.T) {
    14  	// Decode and encode fundingCoinID
    15  	var address [20]byte
    16  	copy(address[:], encode.RandomBytes(20))
    17  	originalFundingCoin := &fundingCoin{
    18  		addr: address,
    19  		amt:  100,
    20  	}
    21  	encodedFundingCoin := originalFundingCoin.RecoveryID()
    22  	decodedFundingCoin, err := decodeFundingCoin(encodedFundingCoin)
    23  	if err != nil {
    24  		t.Fatalf("unexpected error decoding swap coin: %v", err)
    25  	}
    26  	if !bytes.Equal(originalFundingCoin.addr[:], decodedFundingCoin.addr[:]) {
    27  		t.Fatalf("expected address to be equal before and after decoding")
    28  	}
    29  	if originalFundingCoin.amt != decodedFundingCoin.amt {
    30  		t.Fatalf("expected amount to be equal before and after decoding")
    31  	}
    32  
    33  	// Decode amount coin id with incorrect length
    34  	fundingCoinID := make([]byte, 35)
    35  	copy(fundingCoinID, encode.RandomBytes(35))
    36  	if _, err := decodeFundingCoin(fundingCoinID); err == nil {
    37  		t.Fatalf("expected error decoding amount coin ID with incorrect length")
    38  	}
    39  }