Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix bug, args for tx is missing, get args from task #41

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pkg/hlf/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/anoideaopen/channel-transfer/pkg/logger"
"github.com/anoideaopen/channel-transfer/pkg/model"
"github.com/anoideaopen/common-component/errorshlp"
"github.com/anoideaopen/foundation/proto"
"github.com/anoideaopen/glog"
"github.com/go-errors/errors"
"github.com/hyperledger/fabric-protos-go/common"
Expand Down Expand Up @@ -141,7 +142,7 @@ func (p *Parser) extractTxs(blockNum uint64, txs []prsTx) ([]model.Transaction,
BlockNum: blockNum,
TxID: task.GetId(),
FuncName: tsResponse.GetMethod(),
Args: nil,
Args: argsFromTask(task),
TimeNs: 0,
ValidationCode: tx.validationCode,
BatchResponse: tsResponse,
Expand Down Expand Up @@ -173,3 +174,11 @@ func (p *Parser) extractTxs(blockNum uint64, txs []prsTx) ([]model.Transaction,

return tOperations, nil
}

func argsFromTask(task *proto.Task) [][]byte {
argsBytes := [][]byte{[]byte(task.GetMethod())}
for _, arg := range task.GetArgs() {
argsBytes = append(argsBytes, []byte(arg))
}
return argsBytes
}
21 changes: 13 additions & 8 deletions pkg/hlf/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
)

func newBlock(channel, txId string, txMethod string) *common.Block {
func newBlock(channel, txId string, txMethod string, args []string) *common.Block {
task := batcher.NewTaskBuilder().
SetID(txId).
SetMethod(txMethod).
SetArgs([]string{"arg1", "arg2"}).
SetArgs(args).
Build()

executeTasksRequest := batcher.NewExecuteTasksRequestBuilder().
Expand Down Expand Up @@ -114,17 +114,17 @@ func newBlock(channel, txId string, txMethod string) *common.Block {

func TestExtractData_ExecuteTasksMethod(t *testing.T) {
var (
channel string = "test-channel"
channel = "test-channel"
blockNum uint64 = 1
txId string = "unique-task-id"
funcName string = "deleteCCTransferTo"
args [][]uint8
txId = "unique-task-id"
funcName = "deleteCCTransferTo"
args = []string{"arg1", "arg2"}
timeNs uint64 = 0
validationCode int32 = 0
response *peer.Response
)

block := newBlock(channel, txId, funcName)
block := newBlock(channel, txId, funcName, args)

ctx := context.Background()

Expand All @@ -146,7 +146,12 @@ func TestExtractData_ExecuteTasksMethod(t *testing.T) {
assert.Equal(t, blockNum, tx.BlockNum)
assert.Equal(t, txId, tx.TxID)
assert.Equal(t, funcName, tx.FuncName)
assert.Equal(t, args, tx.Args)

expectedArgs := [][]byte{[]byte(funcName)}
for _, arg := range args {
expectedArgs = append(expectedArgs, []byte(arg))
}
assert.Equal(t, expectedArgs, tx.Args)
assert.Equal(t, timeNs, tx.TimeNs)
assert.Equal(t, validationCode, tx.ValidationCode)
assert.NotNil(t, tx.BatchResponse)
Expand Down