-
Notifications
You must be signed in to change notification settings - Fork 3
596 multisig skeleton #597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,008
−103
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f9d4ff8
#596 add multisignature transaction body
andy-shi88 d8a7fd1
#596 add constants for MultiSignature body fields
andy-shi88 7e27313
#596 add multisignature tx body
andy-shi88 35d8c63
#596 add multisignature tx body
andy-shi88 107c771
#596 add multisignature tx type skeleton
andy-shi88 c9bebf4
#596 add multisig tx type enum
andy-shi88 d8421ca
#596 add command tools for generate multisignature tx and parsing any tx
andy-shi88 77e47e8
#596 basic multisignature parsing functionality
andy-shi88 4fe2d6e
#596 update schema commit
andy-shi88 854b28a
#596 add signature info
andy-shi88 06e8b04
#596 change signature structure
andy-shi88 bbf994c
#596 update signature structure to use map
andy-shi88 7729373
#596 adjust cmd tools to new multisig byte structure
andy-shi88 30a399c
#596 update multisig transaction bytes
andy-shi88 655e644
#596 fix tests
andy-shi88 7b18516
#596 fix typo in cmd description
andy-shi88 a0b6ef8
#596 update schema
andy-shi88 f91524e
#596 fix schema conflict
andy-shi88 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package parser | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/zoobc/zoobc-core/common/transaction" | ||
) | ||
|
||
var ( | ||
/* | ||
Transaction Parser Command | ||
*/ | ||
txParserCmd = &cobra.Command{ | ||
Use: "tx", | ||
Short: "parse transaction from its hex representation", | ||
Long: "transaction parser to check the content of your transaction hex", | ||
} | ||
) | ||
|
||
func init() { | ||
txParserCmd.Flags().StringVar(&parserTxHex, "transaction-hex", "", "hex string of the transaction bytes") | ||
txParserCmd.Flags().StringVar(&parserTxBytes, "transaction-bytes", "", "transaction bytes separated by `, `. eg:"+ | ||
"--transaction-bytes='1, 222, 54, 12, 32'") | ||
} | ||
|
||
func Commands() *cobra.Command { | ||
txParserCmd.Run = ParseTransaction | ||
return txParserCmd | ||
} | ||
|
||
func ParseTransaction(*cobra.Command, []string) { | ||
var txBytes []byte | ||
if parserTxHex != "" { | ||
txBytes, _ = hex.DecodeString(parserTxHex) | ||
} else { | ||
txByteCharSlice := strings.Split(parserTxBytes, ", ") | ||
for _, v := range txByteCharSlice { | ||
byteValue, err := strconv.Atoi(v) | ||
if err != nil { | ||
panic("failed to parse transaction bytes") | ||
} | ||
txBytes = append(txBytes, byte(byteValue)) | ||
} | ||
} | ||
tx, err := (&transaction.Util{}).ParseTransactionBytes(txBytes, false) | ||
if err != nil { | ||
panic("error parsing tx" + err.Error()) | ||
} | ||
tx.TransactionBody, err = (&transaction.MultiSignatureTransaction{}).ParseBodyBytes(tx.TransactionBodyBytes) | ||
if err != nil { | ||
panic("error parsing tx body" + err.Error()) | ||
} | ||
fmt.Printf("transaction:\n%v\n", tx) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package parser | ||
|
||
var ( | ||
// txParser | ||
parserTxHex string | ||
parserTxBytes string | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule schema
updated
4 files
+113 −0 | documentation.swagger.json | |
+15 −0 | model/multiSignature.proto | |
+25 −2 | model/transaction.proto | |
+6 −0 | service/transaction.proto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
package transaction | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/zoobc/zoobc-core/common/constant" | ||
"github.com/zoobc/zoobc-core/common/fee" | ||
"github.com/zoobc/zoobc-core/common/model" | ||
"github.com/zoobc/zoobc-core/common/util" | ||
) | ||
|
||
type ( | ||
// MultiSignatureTransaction represent wrapper transaction type that require multiple signer to approve the transcaction | ||
// wrapped | ||
MultiSignatureTransaction struct { | ||
Body *model.MultiSignatureTransactionBody | ||
NormalFee fee.FeeModelInterface | ||
} | ||
) | ||
|
||
func (*MultiSignatureTransaction) ApplyConfirmed(blockTimestamp int64) error { | ||
return nil | ||
} | ||
|
||
func (*MultiSignatureTransaction) ApplyUnconfirmed() error { | ||
return nil | ||
} | ||
|
||
func (*MultiSignatureTransaction) UndoApplyUnconfirmed() error { | ||
return nil | ||
} | ||
|
||
// Validate dbTx specify whether validation should read from transaction state or db state | ||
func (*MultiSignatureTransaction) Validate(dbTx bool) error { | ||
return nil | ||
} | ||
|
||
func (tx *MultiSignatureTransaction) GetMinimumFee() (int64, error) { | ||
minFee, err := tx.NormalFee.CalculateTxMinimumFee(tx.Body, nil) | ||
if err != nil { | ||
return 0, err | ||
} | ||
return minFee, err | ||
} | ||
|
||
func (*MultiSignatureTransaction) GetAmount() int64 { | ||
return 0 | ||
} | ||
|
||
func (tx *MultiSignatureTransaction) GetSize() uint32 { | ||
var ( | ||
txByteSize, signaturesSize, multisigInfoSize uint32 | ||
) | ||
// MultisigInfo | ||
multisigInfo := tx.Body.GetMultiSignatureInfo() | ||
multisigInfoSize += constant.MultisigFieldLength | ||
if multisigInfo != nil { | ||
multisigInfoSize += constant.MultiSigInfoMinSignature | ||
multisigInfoSize += constant.MultiSigInfoNonce | ||
multisigInfoSize += constant.MultiSigNumberOfAddress | ||
for _, v := range multisigInfo.GetAddresses() { | ||
multisigInfoSize += constant.MultiSigAddressLength | ||
multisigInfoSize += uint32(len([]byte(v))) | ||
} | ||
} | ||
// TransactionBytes | ||
txByteSize = constant.MultiSigUnsignedTxBytesLength + uint32(len(tx.Body.GetUnsignedTransactionBytes())) | ||
// SignatureInfo | ||
signaturesSize += constant.MultisigFieldLength | ||
if tx.Body.GetSignatureInfo() != nil { | ||
signaturesSize += constant.MultiSigTransactionHash | ||
signaturesSize += constant.MultiSigNumberOfSignatures | ||
for address, sig := range tx.Body.SignatureInfo.Signatures { | ||
signaturesSize += constant.MultiSigSignatureAddressLength | ||
signaturesSize += uint32(len([]byte(address))) | ||
signaturesSize += constant.MultiSigSignatureLength | ||
signaturesSize += uint32(len(sig)) | ||
} | ||
} | ||
|
||
return txByteSize + signaturesSize + multisigInfoSize | ||
} | ||
|
||
func (tx *MultiSignatureTransaction) ParseBodyBytes(txBodyBytes []byte) (model.TransactionBodyInterface, error) { | ||
var ( | ||
addresses []string | ||
signatures = make(map[string][]byte) | ||
multisigInfo *model.MultiSignatureInfo | ||
signatureInfo *model.SignatureInfo | ||
) | ||
bufferBytes := bytes.NewBuffer(txBodyBytes) | ||
// MultisigInfo | ||
multisigInfoPresent := util.ConvertBytesToUint32(bufferBytes.Next(int(constant.MultisigFieldLength))) | ||
if multisigInfoPresent == constant.MultiSigFieldPresent { | ||
minSignatures := util.ConvertBytesToUint32(bufferBytes.Next(int(constant.MultiSigInfoMinSignature))) | ||
nonce := util.ConvertBytesToUint64(bufferBytes.Next(int(constant.MultiSigInfoNonce))) | ||
addressesLength := util.ConvertBytesToUint32(bufferBytes.Next(int(constant.MultiSigNumberOfAddress))) | ||
for i := 0; i < int(addressesLength); i++ { | ||
addressLength := util.ConvertBytesToUint32(bufferBytes.Next(int(constant.MultiSigAddressLength))) | ||
address, err := util.ReadTransactionBytes(bufferBytes, int(addressLength)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
addresses = append(addresses, string(address)) | ||
} | ||
multisigInfo = &model.MultiSignatureInfo{ | ||
MinimumSignatures: minSignatures, | ||
Nonce: int64(nonce), | ||
Addresses: addresses, | ||
} | ||
} | ||
// TransactionBytes | ||
unsignedTxLength := util.ConvertBytesToUint32(bufferBytes.Next(int(constant.MultiSigUnsignedTxBytesLength))) | ||
unsignedTx, err := util.ReadTransactionBytes(bufferBytes, int(unsignedTxLength)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// SignatureInfo | ||
signatureInfoPresent := util.ConvertBytesToUint32(bufferBytes.Next(int(constant.MultisigFieldLength))) | ||
if signatureInfoPresent == constant.MultiSigFieldPresent { | ||
transactionHash, err := util.ReadTransactionBytes(bufferBytes, int(constant.MultiSigTransactionHash)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
signaturesLength := util.ConvertBytesToUint32(bufferBytes.Next(int(constant.MultiSigNumberOfSignatures))) | ||
for i := 0; i < int(signaturesLength); i++ { | ||
addressLength := util.ConvertBytesToUint32(bufferBytes.Next(int(constant.MultiSigAddressLength))) | ||
address, err := util.ReadTransactionBytes(bufferBytes, int(addressLength)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
signatureLength := util.ConvertBytesToUint32(bufferBytes.Next(int(constant.MultiSigSignatureLength))) | ||
signature, err := util.ReadTransactionBytes(bufferBytes, int(signatureLength)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
signatures[string(address)] = signature | ||
} | ||
signatureInfo = &model.SignatureInfo{ | ||
TransactionHash: transactionHash, | ||
Signatures: signatures, | ||
} | ||
} | ||
|
||
return &model.MultiSignatureTransactionBody{ | ||
MultiSignatureInfo: multisigInfo, | ||
UnsignedTransactionBytes: unsignedTx, | ||
SignatureInfo: signatureInfo, | ||
}, nil | ||
} | ||
|
||
func (tx *MultiSignatureTransaction) GetBodyBytes() []byte { | ||
var ( | ||
buffer = bytes.NewBuffer([]byte{}) | ||
) | ||
// Multisig Info | ||
if tx.Body.GetMultiSignatureInfo() != nil { | ||
buffer.Write(util.ConvertUint32ToBytes(constant.MultiSigFieldPresent)) | ||
buffer.Write(util.ConvertUint32ToBytes(tx.Body.GetMultiSignatureInfo().GetMinimumSignatures())) | ||
buffer.Write(util.ConvertUint64ToBytes(uint64(tx.Body.GetMultiSignatureInfo().GetNonce()))) | ||
buffer.Write(util.ConvertUint32ToBytes(uint32(len(tx.Body.GetMultiSignatureInfo().GetAddresses())))) | ||
for _, v := range tx.Body.GetMultiSignatureInfo().GetAddresses() { | ||
buffer.Write(util.ConvertUint32ToBytes(uint32(len([]byte(v))))) | ||
buffer.Write([]byte(v)) | ||
} | ||
} else { | ||
buffer.Write(util.ConvertUint32ToBytes(constant.MultiSigFieldMissing)) | ||
} | ||
// Transaction Bytes | ||
buffer.Write(util.ConvertUint32ToBytes(uint32(len(tx.Body.GetUnsignedTransactionBytes())))) | ||
buffer.Write(tx.Body.GetUnsignedTransactionBytes()) | ||
// SignatureInfo | ||
if tx.Body.GetSignatureInfo() != nil { | ||
buffer.Write(util.ConvertUint32ToBytes(constant.MultiSigFieldPresent)) | ||
buffer.Write(tx.Body.GetSignatureInfo().GetTransactionHash()) | ||
buffer.Write(util.ConvertUint32ToBytes(uint32(len(tx.Body.GetSignatureInfo().GetSignatures())))) | ||
for address, sig := range tx.Body.GetSignatureInfo().GetSignatures() { | ||
buffer.Write(util.ConvertUint32ToBytes(uint32(len([]byte(address))))) | ||
buffer.Write([]byte(address)) | ||
buffer.Write(util.ConvertUint32ToBytes(uint32(len(sig)))) | ||
buffer.Write(sig) | ||
} | ||
} else { | ||
buffer.Write(util.ConvertUint32ToBytes(constant.MultiSigFieldMissing)) | ||
} | ||
|
||
return buffer.Bytes() | ||
} | ||
|
||
func (tx *MultiSignatureTransaction) GetTransactionBody(transaction *model.Transaction) { | ||
transaction.TransactionBody = &model.Transaction_MultiSignatureTransactionBody{ | ||
MultiSignatureTransactionBody: tx.Body, | ||
} | ||
} | ||
|
||
func (*MultiSignatureTransaction) SkipMempoolTransaction(selectedTransactions []*model.Transaction) (bool, error) { | ||
return false, nil | ||
} | ||
|
||
func (*MultiSignatureTransaction) Escrowable() (EscrowTypeAction, bool) { | ||
return nil, false | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
package transaction | ||
|
||
import ( | ||
"math/rand" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/zoobc/zoobc-core/common/constant" | ||
|
||
"github.com/zoobc/zoobc-core/common/fee" | ||
"github.com/zoobc/zoobc-core/common/model" | ||
) | ||
|
||
func TestMultiSignatureTransaction_GetSize(t *testing.T) { | ||
type fields struct { | ||
Body *model.MultiSignatureTransactionBody | ||
NormalFee fee.FeeModelInterface | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
want uint32 | ||
}{ | ||
{ | ||
name: "GetSize-Success-no_addresses-no_signatures-no_transactionBytes", | ||
fields: fields{ | ||
Body: &model.MultiSignatureTransactionBody{ | ||
MultiSignatureInfo: &model.MultiSignatureInfo{ | ||
MinimumSignatures: rand.Uint32(), | ||
Nonce: rand.Int63(), | ||
Addresses: nil, | ||
}, | ||
UnsignedTransactionBytes: nil, | ||
SignatureInfo: nil, | ||
}, | ||
NormalFee: nil, | ||
}, | ||
want: constant.MultisigFieldLength + constant.MultiSigInfoMinSignature + constant.MultiSigInfoNonce + | ||
constant.MultiSigNumberOfAddress + constant.MultiSigUnsignedTxBytesLength + constant.MultisigFieldLength, | ||
}, | ||
{ | ||
name: "GetSize-Success-with_addresses-no_signatures-no_transactionBytes", | ||
fields: fields{ | ||
Body: &model.MultiSignatureTransactionBody{ | ||
MultiSignatureInfo: &model.MultiSignatureInfo{ | ||
MinimumSignatures: rand.Uint32(), | ||
Nonce: rand.Int63(), | ||
Addresses: []string{ | ||
"A", | ||
}, | ||
}, | ||
UnsignedTransactionBytes: nil, | ||
SignatureInfo: nil, | ||
}, | ||
NormalFee: nil, | ||
}, | ||
want: constant.MultisigFieldLength + constant.MultiSigInfoMinSignature + constant.MultiSigInfoNonce + | ||
constant.MultiSigNumberOfAddress + constant.MultiSigUnsignedTxBytesLength + constant.MultisigFieldLength + | ||
constant.MultiSigAddressLength + uint32(len([]byte("A"))), | ||
}, | ||
{ | ||
name: "GetSize-Success-with_addresses-with_signatures-no_transactionBytes", | ||
fields: fields{ | ||
Body: &model.MultiSignatureTransactionBody{ | ||
MultiSignatureInfo: &model.MultiSignatureInfo{ | ||
MinimumSignatures: rand.Uint32(), | ||
Nonce: rand.Int63(), | ||
Addresses: []string{ | ||
"A", | ||
}, | ||
}, | ||
UnsignedTransactionBytes: nil, | ||
SignatureInfo: &model.SignatureInfo{ | ||
TransactionHash: make([]byte, constant.MultiSigTransactionHash), | ||
Signatures: map[string][]byte{ | ||
"A": make([]byte, 64), | ||
}, | ||
}, | ||
}, | ||
NormalFee: nil, | ||
}, | ||
want: constant.MultisigFieldLength + constant.MultiSigInfoMinSignature + constant.MultiSigInfoNonce + | ||
constant.MultiSigNumberOfAddress + constant.MultiSigAddressLength + uint32(len([]byte("A"))) + | ||
constant.MultiSigUnsignedTxBytesLength + constant.MultisigFieldLength + constant.MultiSigTransactionHash + | ||
constant.MultiSigNumberOfSignatures + constant.MultiSigAddressLength + uint32(len([]byte("A"))) + | ||
constant.MultiSigSignatureLength + 64, | ||
}, | ||
{ | ||
name: "GetSize-Success-with_addresses-with_signatures-with_transactionBytes", | ||
fields: fields{ | ||
Body: &model.MultiSignatureTransactionBody{ | ||
MultiSignatureInfo: &model.MultiSignatureInfo{ | ||
MinimumSignatures: rand.Uint32(), | ||
Nonce: rand.Int63(), | ||
Addresses: []string{ | ||
"A", | ||
}, | ||
}, | ||
UnsignedTransactionBytes: make([]byte, 120), | ||
SignatureInfo: &model.SignatureInfo{ | ||
TransactionHash: make([]byte, constant.MultiSigTransactionHash), | ||
Signatures: map[string][]byte{ | ||
"A": make([]byte, 64), | ||
}, | ||
}, | ||
}, | ||
NormalFee: nil, | ||
}, | ||
want: constant.MultisigFieldLength + constant.MultiSigInfoMinSignature + constant.MultiSigInfoNonce + | ||
constant.MultiSigNumberOfAddress + constant.MultiSigAddressLength + uint32(len([]byte("A"))) + | ||
constant.MultisigFieldLength + constant.MultiSigTransactionHash + constant.MultiSigNumberOfSignatures + | ||
constant.MultiSigAddressLength + uint32(len([]byte("A"))) + | ||
constant.MultiSigSignatureLength + 64 + | ||
constant.MultiSigUnsignedTxBytesLength + 120, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tx := &MultiSignatureTransaction{ | ||
Body: tt.fields.Body, | ||
NormalFee: tt.fields.NormalFee, | ||
} | ||
if got := tx.GetSize(); got != tt.want { | ||
t.Errorf("GetSize() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
var ( | ||
// mock for GetBodyBytes & ParseBodyBytes | ||
mockMultipleSignatureBody = &model.MultiSignatureTransactionBody{ | ||
MultiSignatureInfo: &model.MultiSignatureInfo{ | ||
MinimumSignatures: 2, | ||
Nonce: 1, | ||
Addresses: []string{ | ||
"A", | ||
"B", | ||
"C", | ||
}, | ||
}, | ||
UnsignedTransactionBytes: make([]byte, 120), | ||
SignatureInfo: &model.SignatureInfo{ | ||
TransactionHash: make([]byte, constant.MultiSigTransactionHash), | ||
Signatures: map[string][]byte{ | ||
"A": make([]byte, 64), | ||
}, | ||
}, | ||
} | ||
mockMultipleSignatureBodyBytes = []byte{ | ||
1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 65, 1, 0, 0, 0, 66, 1, 0, 0, 0, | ||
67, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 65, 64, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
} | ||
// mock for GetBodyBytes & ParseBodyBytes | ||
) | ||
|
||
func TestMultiSignatureTransaction_GetBodyBytes(t *testing.T) { | ||
type fields struct { | ||
Body *model.MultiSignatureTransactionBody | ||
NormalFee fee.FeeModelInterface | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
want []byte | ||
}{ | ||
{ | ||
name: "GetBodyBytes-Success", | ||
fields: fields{ | ||
Body: nil, | ||
NormalFee: nil, | ||
}, | ||
want: make([]byte, 12), | ||
}, | ||
{ | ||
name: "GetBodyBytes-Success-Complete", | ||
fields: fields{ | ||
Body: mockMultipleSignatureBody, | ||
NormalFee: nil, | ||
}, | ||
want: mockMultipleSignatureBodyBytes, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tx := &MultiSignatureTransaction{ | ||
Body: tt.fields.Body, | ||
NormalFee: tt.fields.NormalFee, | ||
} | ||
if got := tx.GetBodyBytes(); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("GetBodyBytes() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestMultiSignatureTransaction_ParseBodyBytes(t *testing.T) { | ||
type fields struct { | ||
Body *model.MultiSignatureTransactionBody | ||
NormalFee fee.FeeModelInterface | ||
} | ||
type args struct { | ||
txBodyBytes []byte | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want model.TransactionBodyInterface | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "ParseBodyBytes-success", | ||
fields: fields{ | ||
Body: nil, | ||
NormalFee: nil, | ||
}, | ||
args: args{ | ||
txBodyBytes: mockMultipleSignatureBodyBytes, | ||
}, | ||
want: mockMultipleSignatureBody, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tx := &MultiSignatureTransaction{ | ||
Body: tt.fields.Body, | ||
NormalFee: tt.fields.NormalFee, | ||
} | ||
got, err := tx.ParseBodyBytes(tt.args.txBodyBytes) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("ParseBodyBytes() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ParseBodyBytes() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.