github.com/eris-ltd/erisdb@v0.25.0/execution/transactor_test.go (about) 1 // Copyright 2017 Monax Industries Limited 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package execution 16 17 import ( 18 "context" 19 "testing" 20 21 "github.com/hyperledger/burrow/acm" 22 "github.com/hyperledger/burrow/acm/acmstate" 23 "github.com/hyperledger/burrow/bcm" 24 "github.com/hyperledger/burrow/consensus/tendermint/codes" 25 "github.com/hyperledger/burrow/crypto" 26 "github.com/hyperledger/burrow/event" 27 "github.com/hyperledger/burrow/execution/exec" 28 "github.com/hyperledger/burrow/keys/mock" 29 "github.com/hyperledger/burrow/logging" 30 "github.com/hyperledger/burrow/txs" 31 "github.com/hyperledger/burrow/txs/payload" 32 "github.com/stretchr/testify/assert" 33 "github.com/stretchr/testify/require" 34 abciTypes "github.com/tendermint/tendermint/abci/types" 35 tmTypes "github.com/tendermint/tendermint/types" 36 ) 37 38 func TestTransactor_BroadcastTxSync(t *testing.T) { 39 chainID := "TestChain" 40 bc := &bcm.Blockchain{} 41 evc := event.NewEmitter() 42 evc.SetLogger(logging.NewNoopLogger()) 43 txCodec := txs.NewAminoCodec() 44 privAccount := acm.GeneratePrivateAccountFromSecret("frogs") 45 tx := &payload.CallTx{ 46 Input: &payload.TxInput{ 47 Address: privAccount.GetAddress(), 48 }, 49 Address: &crypto.Address{1, 2, 3}, 50 } 51 txEnv := txs.Enclose(chainID, tx) 52 err := txEnv.Sign(privAccount) 53 require.NoError(t, err) 54 height := uint64(35) 55 trans := NewTransactor(bc, evc, NewAccounts(acmstate.NewMemoryState(), mock.NewKeyClient(privAccount), 100), 56 func(tx tmTypes.Tx, cb func(*abciTypes.Response)) error { 57 txe := exec.NewTxExecution(txEnv) 58 txe.Height = height 59 err := evc.Publish(context.Background(), txe, txe.Tagged()) 60 if err != nil { 61 return err 62 } 63 bs, err := txe.Receipt.Encode() 64 if err != nil { 65 return err 66 } 67 cb(abciTypes.ToResponseCheckTx(abciTypes.ResponseCheckTx{ 68 Code: codes.TxExecutionSuccessCode, 69 Data: bs, 70 })) 71 return nil 72 }, txCodec, logger) 73 txe, err := trans.BroadcastTxSync(context.Background(), txEnv) 74 require.NoError(t, err) 75 assert.Equal(t, height, txe.Height) 76 }