github.com/amazechain/amc@v0.1.3/accounts/accounts_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 accounts 18 19 import ( 20 "bytes" 21 "github.com/amazechain/amc/common/crypto" 22 "github.com/amazechain/amc/common/math" 23 "github.com/ledgerwatch/secp256k1" 24 "testing" 25 26 "github.com/amazechain/amc/common/hexutil" 27 ) 28 29 func TestTextHash(t *testing.T) { 30 hash := TextHash([]byte("Hello Joe")) 31 want := hexutil.MustDecode("0xa080337ae51c4e064c189e113edd0ba391df9206e2f49db658bb32cf2911730b") 32 if !bytes.Equal(hash, want) { 33 t.Fatalf("wrong hash: %x", hash) 34 } 35 } 36 37 func TestSign(t *testing.T) { 38 private, err := crypto.HexToECDSA("DEBF9EAE7820E23201EEE9D51413B6D2CDF06C320D7152C2D3BC1FB6C42DA23D") 39 if nil != err { 40 t.Error(err) 41 } 42 seckey := math.PaddedBigBytes(private.D, private.Params().BitSize/8) 43 defer zeroBytes(seckey) 44 45 msg, _ := hexutil.Decode("0x08712134afd46d42a45a5ed0e9311933138a06041b88062e590a613c2673c29f") 46 signature, err := secp256k1.Sign(msg, seckey) 47 48 t.Logf("%v", err) 49 t.Logf("%s", hexutil.Encode(signature)) 50 } 51 52 func zeroBytes(bytes []byte) { 53 for i := range bytes { 54 bytes[i] = 0 55 } 56 }