fixup abci clie

This commit is contained in:
William Banfield
2022-08-18 16:16:47 -04:00
parent 06eb1c5a4b
commit 4fa4ababa4
5 changed files with 18 additions and 34 deletions
+7 -19
View File
@@ -332,9 +332,7 @@ func cmdTest(cmd *cobra.Command, args []string) error {
func() error {
return servertest.PrepareProposal(client, [][]byte{
{0x01},
}, []types.TxRecord_TxAction{
types.TxRecord_UNMODIFIED,
}, nil)
}, [][]byte{{0x01}}, nil)
},
func() error {
return servertest.ProcessProposal(client, [][]byte{
@@ -638,22 +636,12 @@ func cmdPrepareProposal(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
resps := make([]response, 0, len(res.TxRecords)+1)
for _, tx := range res.TxRecords {
existingTx := inTxArray(txsBytesArray, tx.Tx)
if tx.Action == types.TxRecord_UNKNOWN ||
(existingTx && tx.Action == types.TxRecord_ADDED) ||
(!existingTx && (tx.Action == types.TxRecord_UNMODIFIED || tx.Action == types.TxRecord_REMOVED)) {
resps = append(resps, response{
Code: codeBad,
Log: "Failed. Tx: " + string(tx.GetTx()) + " action: " + tx.Action.String(),
})
} else {
resps = append(resps, response{
Code: code.CodeTypeOK,
Log: "Succeeded. Tx: " + string(tx.Tx) + " action: " + tx.Action.String(),
})
}
resps := make([]response, 0, len(res.Txs))
for _, tx := range res.Txs {
resps = append(resps, response{
Code: code.CodeTypeOK,
Log: "Succeeded. Tx: " + string(tx),
})
}
printResponse(cmd, args, resps...)
+2 -4
View File
@@ -310,9 +310,7 @@ const (
ReplacePrefix = "replace"
)
func isPrepareTx(tx []byte) bool {
return bytes.HasPrefix(tx, []byte(PreparePrefix))
}
func isPrepareTx(tx []byte) bool { return bytes.HasPrefix(tx, []byte(PreparePrefix)) }
func isReplacedTx(tx []byte) bool {
return bytes.HasPrefix(tx, []byte(ReplacePrefix))
@@ -339,7 +337,7 @@ func (app *PersistentKVStoreApplication) substPrepareTx(blockData [][]byte, maxT
if totalBytes > maxTxBytes {
break
}
txs = append(txs, tx)
txs = append(txs, txMod)
}
return txs
}
+5 -5
View File
@@ -65,13 +65,13 @@ func DeliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []
return nil
}
func PrepareProposal(client abcicli.Client, txBytes [][]byte, codeExp []types.TxRecord_TxAction, dataExp []byte) error {
func PrepareProposal(client abcicli.Client, txBytes [][]byte, txExpected [][]byte, dataExp []byte) error {
res, _ := client.PrepareProposalSync(types.RequestPrepareProposal{Txs: txBytes})
for i, tx := range res.TxRecords {
if tx.Action != codeExp[i] {
for i, tx := range res.Txs {
if !bytes.Equal(tx, txExpected[i]) {
fmt.Println("Failed test: PrepareProposal")
fmt.Printf("PrepareProposal response code was unexpected. Got %v expected %v.",
tx.Action, codeExp)
fmt.Printf("PrepareProposal transaction was unexpected. Got %x expected %x.",
tx, txExpected[i])
return errors.New("PrepareProposal error")
}
}
+1 -1
View File
@@ -11,7 +11,7 @@ deliver_tx "def=xyz"
commit
query "def"
prepare_proposal "preparedef"
process_proposal "def"
process_proposal "replacedef"
process_proposal "preparedef"
prepare_proposal
process_proposal
+3 -5
View File
@@ -10,7 +10,7 @@
> prepare_proposal "abc"
-> code: OK
-> log: Succeeded. Tx: abc action: UNMODIFIED
-> log: Succeeded. Tx: abc
> process_proposal "abc"
-> code: OK
@@ -59,11 +59,9 @@
> prepare_proposal "preparedef"
-> code: OK
-> log: Succeeded. Tx: def action: ADDED
-> code: OK
-> log: Succeeded. Tx: preparedef action: REMOVED
-> log: Succeeded. Tx: replacedef
> process_proposal "def"
> process_proposal "replacedef"
-> code: OK
-> status: ACCEPT