diff --git a/client/client_mock_test.go b/client/client_mock.go similarity index 73% rename from client/client_mock_test.go rename to client/client_mock.go index fbd5bc956bad71ad56dda184b0f439978c886ec4..249001acc1969dbf255c8d0c033802aea13344e4 100644 --- a/client/client_mock_test.go +++ b/client/client_mock.go @@ -17,26 +17,24 @@ package client import ( - "fmt" - "github.com/tendermint/go-crypto" - "gthub.com/eris-ltd/eris-db/account" + acc "github.com/eris-ltd/eris-db/account" "github.com/eris-ltd/eris-db/txs" ) // NOTE [ben] Compiler check to ensure ErisMockClient successfully implements // eris-db/client.NodeClient -var _ NodeClient = (*ErisMockClient)(nil) +var _ NodeClient = (*MockNodeClient)(nil) type MockNodeClient struct { - accounts map[string]*account.Account + accounts map[string]*acc.Account } func NewMockNodeClient() *MockNodeClient { return &MockNodeClient{ - accounts: make(map[string]*account.Account) + accounts: make(map[string]*acc.Account), } } @@ -46,28 +44,28 @@ func (mock *MockNodeClient) Broadcast(transaction txs.Tx) (*txs.Receipt, error) txReceipt := &txs.Receipt{ TxHash: make([]byte, 20, 20), CreatesContract: 0, - ContractAddr: make([]byte, 20, 20) + ContractAddr: make([]byte, 20, 20), } return txReceipt, nil } -func (mock *MockNodeClient) GetAccount(address []byte) (*account.Account, error) { +func (mock *MockNodeClient) GetAccount(address []byte) (*acc.Account, error) { // make zero account var zero [32]byte copyAddressBytes := make([]byte, len(address), len(address)) copy(copyAddressBytes, address) - account := &account.Account{ + account := &acc.Account{ Address: copyAddressBytes, - PubKey: crypto.PubKey(crypto.PubKeyEd28819(zero)), + PubKey: crypto.PubKey(crypto.PubKeyEd25519(zero)), Sequence: 0, Balance: 0, - Code: make([]byte, 0) - StorageRoot: make([]byte, 0] + Code: make([]byte, 0), + StorageRoot: make([]byte, 0), } return account, nil } -func (mock *MockNodeClient) MockAddAccount(account *account.Account) { +func (mock *MockNodeClient) MockAddAccount(account *acc.Account) { addressString := string(account.Address[:]) - mock.accounts[addressString] := account.Copy() + mock.accounts[addressString] = account.Copy() } \ No newline at end of file diff --git a/client/core/transaction_factory.go b/client/core/transaction_factory.go index 2e85dcbbaf244f44ca3c4760803157de1237cf78..acb1db0095439eaa8f9e86073196dcef1483130e 100644 --- a/client/core/transaction_factory.go +++ b/client/core/transaction_factory.go @@ -50,6 +50,8 @@ func Send(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addr, return nil, fmt.Errorf("destination address must be given with --to flag") } + fmt.Printf("from address: %s", addr) + fmt.Printf("to address: %s", toAddr) toAddrBytes, err := hex.DecodeString(toAddr) if err != nil { return nil, fmt.Errorf("toAddr is bad hex: %v", err) diff --git a/client/core/transaction_factory_test.go b/client/core/transaction_factory_test.go index b46bdc7f83d05b6f7d4ee6423ef18fb29a0fd59f..3a9185fbe8a187506b79ca000d582116f922943b 100644 --- a/client/core/transaction_factory_test.go +++ b/client/core/transaction_factory_test.go @@ -17,10 +17,9 @@ package core import ( + "fmt" "testing" - "github.com/eris-ltd/eris-keys/crypto" - "github.com/eris-ltd/eris-db/client" "github.com/eris-ltd/eris-db/keys" ) @@ -29,20 +28,20 @@ import ( // modularise and restructure the components of the code. -func TestTransactionFactory(t *testing.T) { - // test in parallel - t.Run("ExtractInputAddress from transaction", func (t *testing.T) { - t.Run("SendTransaction", testTransactionFactorySend) - // t.Run("NameTransaction", ) - // t.Run("CallTransaction", ) - // t.Run("PermissionTransaction", ) - // t.Run("BondTransaction", ) - // t.Run("UnbondTransaction", ) - // t.Run("RebondTransaction", ) - }) -} +// func TestTransactionFactory(t *testing.T) { +// // test in parallel +// t.Run("ExtractInputAddress from transaction", func (t1 *testing.T) { +// t1.Run("SendTransaction", testTransactionFactorySend) +// // t.Run("NameTransaction", ) +// // t.Run("CallTransaction", ) +// // t.Run("PermissionTransaction", ) +// // t.Run("BondTransaction", ) +// // t.Run("UnbondTransaction", ) +// // t.Run("RebondTransaction", ) +// }) +// } -func testTransactionFactorySend(t *testing.T) { +func TestTransactionFactorySend(t *testing.T) { mockKeyClient := keys.NewMockKeyClient() mockNodeClient := client.NewMockNodeClient() @@ -61,9 +60,10 @@ func testTransactionFactorySend(t *testing.T) { // set nonce to unset nonce := "" - tx, err := Send(mockNodeClient, mockKeyClient, publicKey, string(address), - string(toAddress), amount, nonce) + _, err := Send(mockNodeClient, mockKeyClient, publicKey, fmt.Sprintf("%X", address), + fmt.Sprintf("%X", toAddress), amount, nonce) if err != nil { + t.Logf("Error: %s", err) t.Fail() } } diff --git a/client/core/transaction_factory_util.go b/client/core/transaction_factory_util.go index f119ef9a3391ddfbdce43ce592198e99c5fb3a2e..28aa4643a2e094526420bb3fccb86ac06766d707 100644 --- a/client/core/transaction_factory_util.go +++ b/client/core/transaction_factory_util.go @@ -37,7 +37,7 @@ import ( // tx has either one input or we default to the first one (ie for send/bond) // TODO: better support for multisig and bonding func signTx(keyClient keys.KeyClient, chainID string, tx_ txs.Tx) ([]byte, txs.Tx, error) { - signString := fmt.Sprintf("%X", acc.SignBytes(chainID, tx_)) + signBytes := []byte(fmt.Sprintf("%X", acc.SignBytes(chainID, tx_))) var inputAddr []byte var sigED crypto.SignatureEd25519 switch tx := tx_.(type) { @@ -66,18 +66,17 @@ func signTx(keyClient keys.KeyClient, chainID string, tx_ txs.Tx) ([]byte, txs.T inputAddr = tx.Address defer func(s *crypto.SignatureEd25519) { tx.Signature = *s }(&sigED) } - sig, err := keyClient.Sign(signString, inputAddr) + sig, err := keyClient.Sign(signBytes, inputAddr) if err != nil { return nil, nil, err } - // because this codebase has been written with a total neglect for the type - // system, this is an intermediate step before we clean out the full set of - // canonical bytes. + // TODO: [ben] temporarily address the type conflict here, to be cleaned up + // with full type restructuring var sig64 [64]byte copy(sig64[:], sig) sigED = crypto.SignatureEd25519(sig64) log.WithFields(log.Fields{ - "transaction sign bytes": signString, + "transaction sign bytes": fmt.Sprintf("%X", signBytes), "account address": fmt.Sprintf("%X", inputAddr), "signature": fmt.Sprintf("%X", sig64), }).Debug("Signed transaction") @@ -148,9 +147,9 @@ func checkCommon(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, } } else { // grab the pubkey from eris-keys - pubKeyBytes, err = keyClient.PublicKey(addr) + pubKeyBytes, err = keyClient.PublicKey([]byte(addr)) if err != nil { - err = fmt.Errorf("failed to fetch pubkey for address (%s): %v", addr, err) + err = fmt.Errorf("failed to fetch pubkey for address (%X): %v", addr, err) return } diff --git a/glide.lock b/glide.lock index a1ff19dac28f6ca7a7526162d3fbc29cf4a710bb..8014bc99f9a0ae8a20de92413fb8fbcbe023c1ae 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: 11dc81a6cb059737f9fb51d33ea7d80dd6edfa1f4293f6b4b74507011a536f32 -updated: 2016-06-21T11:22:28.775429287+01:00 +hash: f1f85c5d4b9520217cc6fa9fd7b7e97790e737def9bc08ab45d53d5db729c779 +updated: 2016-09-14T20:54:48.289839938+02:00 imports: - name: github.com/Azure/go-ansiterm version: 388960b655244e76e24c75f48631564eaefade62 @@ -21,14 +21,22 @@ imports: version: d6191e27ad06236eaad65d79e49a08b03b9f8029 - name: github.com/BurntSushi/toml version: f0aeabca5a127c4078abb8c8d64298b147264b55 +- name: github.com/davecgh/go-spew + version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d + subpackages: + - spew - name: github.com/docker/docker version: 097d1a2b6186dcf1df8ae6135470871aca309a31 subpackages: + - pkg/ioutils - pkg/term + - pkg/longpath - pkg/system - pkg/term/windows - name: github.com/docker/go-units version: f2d77a61e3c169b43402a0a1e84f06daf29b8190 +- name: github.com/eris-ltd/eris-keys + version: 114ebc77443db9a153692233294e48bc7e184215 - name: github.com/eris-ltd/eris-logger version: ea48a395d6ecc0eccc67a26da9fc7a6106fabb84 - name: github.com/fsnotify/fsnotify @@ -73,6 +81,10 @@ imports: version: d2dd0262208475919e1a362f675cfc0e7c10e905 - name: github.com/naoina/toml version: 751171607256bb66e64c9f0220c00662420c38e9 +- name: github.com/pmezard/go-difflib + version: d8ed2627bdf02c080bf22230dbb337003b7aba2d + subpackages: + - difflib - name: github.com/Sirupsen/logrus version: f3cfb454f4c209e6668c95216c4744b8fddb2356 - name: github.com/spf13/cast @@ -87,6 +99,8 @@ imports: version: c1ccc378a054ea8d4e38d8c67f6938d4760b53dd - name: github.com/stretchr/testify version: d77da356e56a7428ad25149ca77381849a6a5232 + subpackages: + - assert - name: github.com/syndtr/goleveldb version: fa5b5c78794bc5c18f330361059f871ae8c2b9d6 subpackages: @@ -132,8 +146,8 @@ imports: - name: github.com/tendermint/go-rpc version: 479510be0e80dd9e5d6b1f941adad168df0af85f subpackages: - - server - client + - server - types - name: github.com/tendermint/go-wire version: 3b0adbc86ed8425eaed98516165b6788d9f4de7a @@ -147,13 +161,13 @@ imports: - node - proxy - types + - version - consensus - rpc/core/types - blockchain - mempool - rpc/core - state - - version - name: github.com/tendermint/tmsp version: 73e5c3cb7bbee2f9c49792e5a0fcbcab442bf7dc subpackages: @@ -175,13 +189,14 @@ imports: - openpgp/errors - curve25519 - name: golang.org/x/net - version: 7c71ca708c71bcbd0e6c856b01468ee07fe24557 + version: de35ec43e7a9aabd6a9c54d2898220ea7e44de7d subpackages: - http2 - context - netutil - trace - http2/hpack + - idna - lex/httplex - internal/timeseries - name: golang.org/x/sys diff --git a/keys/key_client.go b/keys/key_client.go index a91f74918350f775269145b62494e2e323434369..8bb14e347c6b101677f65a35f7629cc3981718cd 100644 --- a/keys/key_client.go +++ b/keys/key_client.go @@ -23,9 +23,9 @@ import ( type KeyClient interface{ // Sign needs to return the signature bytes for given message to sign // and the address to sign it with. - Sign(signString string, signAddress []byte) (signature []byte, err error) + Sign(signBytes []byte, signAddress []byte) (signature []byte, err error) // PublicKey needs to return the public key associated with a given address - PublicKey(addressString string) (publicKey []byte, err error) + PublicKey(address []byte) (publicKey []byte, err error) } // NOTE [ben] Compiler check to ensure ErisKeyClient successfully implements @@ -46,10 +46,10 @@ func NewErisKeyClient(rpcString string) *ErisKeyClient{ // Eris-keys client Sign requests the signature from ErisKeysClient over rpc for the given // bytes to be signed and the address to sign them with. -func (erisKeys *ErisKeyClient) Sign(signString string, signAddress []byte) (signature []byte, err error) { +func (erisKeys *ErisKeyClient) Sign(signBytes []byte, signAddress []byte) (signature []byte, err error) { args := map[string]string{ - "msg": signString, - "hash": signString, // TODO:[ben] backwards compatibility + "msg": string(signBytes), + "hash": string(signBytes), // TODO:[ben] backwards compatibility "addr": string(signAddress), } sigS, err := RequestResponse(erisKeys.rpcString, "sign", args) @@ -66,9 +66,9 @@ func (erisKeys *ErisKeyClient) Sign(signString string, signAddress []byte) (sign // Eris-keys client PublicKey requests the public key associated with an address from // the eris-keys server. -func (erisKeys *ErisKeyClient) PublicKey(addressString string) (publicKey []byte, err error) { +func (erisKeys *ErisKeyClient) PublicKey(address []byte) (publicKey []byte, err error) { args := map[string]string{ - "addr": addressString, + "addr": string(address), } pubS, err := RequestResponse(erisKeys.rpcString, "pub", args) if err != nil { diff --git a/keys/key_client_mock_test.go b/keys/key_client_mock.go similarity index 66% rename from keys/key_client_mock_test.go rename to keys/key_client_mock.go index 24b0500d4d9d679dbe8bb857b7aac80c0739b414..a587bbdc9f32e9539dbe2a7ada30ddb9025f1240 100644 --- a/keys/key_client_mock_test.go +++ b/keys/key_client_mock.go @@ -38,30 +38,38 @@ type MockKeyClient struct{ func NewMockKeyClient() *MockKeyClient { return &MockKeyClient{ - knownKeys: make(map[string]*crypto.Key) + knownKeys: make(map[string]*crypto.Key), } } func (mock *MockKeyClient) NewKey() (address []byte) { // Only tests ED25519 curve and ripemd160. keyType := crypto.KeyType{ crypto.CurveTypeEd25519, - AddrTypeRipemd160 } - key, err := crypto.NewKey() - + crypto.AddrTypeRipemd160 } + key, err := crypto.NewKey(keyType) + if err != nil { + panic(fmt.Sprintf("Mocked key client failed on key generation (%s): %s", keyType.String(), err)) + } + pubk, _ := key.Pubkey() + fmt.Printf("generated key %X with address %X", pubk, key.Address) + mock.knownKeys[fmt.Sprintf("%X", key.Address)] = key + return key.Address } -func (mock *MockKeyClient) Sign(signString string, signAddress []byte) (signature []byte, err error) { - key := mock.knownKeys[string(signAddress)] - if key.PrivateKey == nil { +func (mock *MockKeyClient) Sign(signBytes []byte, signAddress []byte) (signature []byte, err error) { + fmt.Printf("on signing with address %X \n", signAddress) + key := mock.knownKeys[fmt.Sprintf("%X", signAddress)] + if key == nil { return nil, fmt.Errorf("Unknown address (%X)", signAddress) } return key.Sign(signBytes) } func (mock *MockKeyClient) PublicKey(address []byte) (publicKey []byte, err error) { - key := mock.knownKeys[string(signAddress)] - if key.PrivateKey == nil { - return nil, fmt.Errorf("Unknown address (%X)", signAddress) + fmt.Printf("on retrieving public key for address %X \n", address) + key := mock.knownKeys[fmt.Sprintf("%X", address)] + if key == nil { + return nil, fmt.Errorf("Unknown address (%X)", address) } - return key.PubKey() + return key.Pubkey() }