github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/identity/integration_test.go (about) 1 /* 2 * Copyright (C) 2017 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU 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 * This program 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 General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package identity 19 20 import ( 21 "testing" 22 23 "github.com/ethereum/go-ethereum/accounts" 24 ethKs "github.com/ethereum/go-ethereum/accounts/keystore" 25 "github.com/ethereum/go-ethereum/common" 26 "github.com/ethereum/go-ethereum/crypto" 27 "github.com/mysteriumnetwork/node/eventbus" 28 "github.com/stretchr/testify/assert" 29 ) 30 31 var ( 32 idAddress = "0x53a835143c0ef3bbcbfa796d7eb738ca7dd28f68" 33 idAccount = accounts.Account{ 34 Address: common.HexToAddress("53a835143c0ef3bbcbfa796d7eb738ca7dd28f68"), 35 } 36 idChainID int64 = 1 37 idKey, _ = crypto.HexToECDSA("6f88637b68ee88816e73f663aef709d7009836c98ae91ef31e3dfac7be3a1657") 38 ) 39 40 func Test_UnlockAndSignAndVerify(t *testing.T) { 41 ks := NewKeystoreFilesystem("dir", ðKeystoreMock{account: idAccount}) 42 ks.loadKey = func(addr common.Address, filename, auth string) (*ethKs.Key, error) { 43 return ðKs.Key{Address: addr, PrivateKey: idKey}, nil 44 } 45 46 bus := eventbus.New() 47 manager := NewIdentityManager(ks, bus, NewResidentCountry(bus, newMockLocationResolver("LT"))) 48 err := manager.Unlock(idChainID, idAddress, "") 49 assert.NoError(t, err) 50 51 signer := NewSigner(ks, FromAddress(idAddress)) 52 signature, err := signer.Sign([]byte("Boop!")) 53 assert.NoError(t, err) 54 assert.Exactly( 55 t, 56 SignatureHex("1f89542f406b2d638fe09cd9912d0b8c0b5ebb4aef67d52ab046973e34fb430a1953576cd19d140eddb099aea34b2985fbd99e716d3b2f96a964141fdb84b32000"), 57 signature, 58 ) 59 60 verifier := NewVerifierIdentity(FromAddress(idAddress)) 61 res, _ := verifier.Verify([]byte("Boop!"), signature) 62 assert.True(t, res) 63 }