github.com/amazechain/amc@v0.1.3/contracts/deposit/contract_test.go (about)

     1  // Copyright 2023 The AmazeChain Authors
     2  // This file is part of the AmazeChain library.
     3  //
     4  // The AmazeChain library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The AmazeChain library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the AmazeChain library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package deposit
    18  
    19  import (
    20  	"github.com/amazechain/amc/common/crypto/bls"
    21  	"github.com/amazechain/amc/common/hexutil"
    22  	"github.com/amazechain/amc/params"
    23  	"github.com/holiman/uint256"
    24  	"testing"
    25  )
    26  
    27  func TestBLS(t *testing.T) {
    28  	sig, _ := hexutil.Decode("0xab22c6b63e3595630ffe8ed2903dfeba2a781c2d33dc66f88442982b65c5fcce9a8078f9ae419c95eecd2a5546a06e371196855311a930a4ad404321083f4f058c41e2d6c2e1f2bf11b1cd9b73d65a0a169a81cc1e60b50164aa7b322396be67")
    29  	bp, _ := hexutil.Decode("0xa20699fa55487f79c1400e2be5bb6acf89b0c5880becfa4b0560b9994bd8050616886a8fb71bdf15065dd31dd2858c18")
    30  	msg := new(uint256.Int).Mul(uint256.NewInt(params.AMT), uint256.NewInt(50)) //50AMT
    31  	signature, err := bls.SignatureFromBytes(sig)
    32  	if err != nil {
    33  		t.Fatal("cannot unpack BLS signature", err)
    34  	}
    35  
    36  	publicKey, err := bls.PublicKeyFromBytes(bp)
    37  
    38  	if err != nil {
    39  		t.Fatal("cannot unpack BLS publicKey", err)
    40  	}
    41  
    42  	if !signature.Verify(publicKey, msg.Bytes()) {
    43  		t.Fatal("bls cannot verify signature")
    44  	}
    45  
    46  }
    47  
    48  func TestUint256(t *testing.T) {
    49  	amt50Hex, _ := hexutil.Decode("0x2B5E3AF16B1880000") // 50 AMT
    50  	amt50Uint256 := new(uint256.Int).Mul(uint256.NewInt(params.AMT), uint256.NewInt(50))
    51  	//
    52  	t.Logf("50 AMT uint256 bytes:%s, hex Bytes: %s", hexutil.Encode(amt50Uint256.Bytes()), hexutil.Encode(amt50Hex))
    53  
    54  	amt500Hex, _ := hexutil.Decode("0x1B1AE4D6E2EF500000") // 500 AMT
    55  	amt500Uint256 := new(uint256.Int).Mul(uint256.NewInt(params.AMT), uint256.NewInt(500))
    56  	//
    57  	t.Logf("500 AMT uint256 bytes:%s, hex Bytes: %s", hexutil.Encode(amt500Uint256.Bytes()), hexutil.Encode(amt500Hex))
    58  
    59  	amt100Hex, _ := hexutil.Decode("0x56BC75E2D63100000") // 100 AMT
    60  	amt100Uint256 := new(uint256.Int).Mul(uint256.NewInt(params.AMT), uint256.NewInt(100))
    61  	//
    62  	t.Logf("100 AMT uint256 bytes:%s, hex Bytes: %s", hexutil.Encode(amt100Uint256.Bytes()), hexutil.Encode(amt100Hex))
    63  }
    64  
    65  //func TestPrivateKey(t *testing.T) {
    66  //	private, _ := hexutil.Decode("0xde4b76c3dca3d8e10aea7644f77b316a68a6476fbd119d441ead5c6131aa42a7")
    67  //
    68  //	p, err := bls.SecretKeyFromBytes(private)
    69  //	if err != nil {
    70  //		t.Fatal("bls cannot import private key", err)
    71  //	}
    72  //
    73  //	pub, err := p.PublicKey().MarshalText()
    74  //
    75  //	if err != nil {
    76  //		t.Fatal("bls public key cannot MarshalText ", err)
    77  //	}
    78  //	t.Logf("pubkey %s", string(pub))
    79  //}