Skip to content

Commit

Permalink
Add unit tests for JSON and RLP encoding/decoding of Celo Transactions (
Browse files Browse the repository at this point in the history
#306)

* Add unit test for Celo Tx JSON marshaling

Format imports

Add test for CeloDenominatedTx

* Add unit test for Celo Tx JSON unmarshaling

* Add unit test for Celo Tx RLP encoding/decoding

* format and clean up unit tests for Celo Tx JSON marshaling/unmarshaling

* Replace assert.NoError with require.NoError

* Adds checks for presence of feeCurrency and maxFeeInFeeCurrency fields during unmarshalling of CeloDenominatedTx
  • Loading branch information
Kourin1996 authored and karlb committed Jan 28, 2025
1 parent 6c6e473 commit 2a94ad3
Show file tree
Hide file tree
Showing 3 changed files with 712 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/types/celo_transaction_marshalling.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func celoTransactionMarshal(tx *Transaction) ([]byte, bool, error) {
enc.Nonce = (*hexutil.Uint64)(&itx.Nonce)
enc.To = tx.To()
enc.Gas = (*hexutil.Uint64)(&itx.Gas)
enc.GasPrice = (*hexutil.Big)(itx.GasPrice)
enc.Value = (*hexutil.Big)(itx.Value)
enc.Input = (*hexutil.Bytes)(&itx.Data)
enc.V = (*hexutil.Big)(itx.V)
Expand Down Expand Up @@ -340,7 +341,13 @@ func celoTransactionUnmarshal(dec txJSON, inner *TxData) (bool, error) {
}
}
// Celo specific fields
if dec.FeeCurrency == nil {
return true, errors.New("missing required field 'feeCurrency' in transaction")
}
itx.FeeCurrency = dec.FeeCurrency
if dec.MaxFeeInFeeCurrency == nil {
return true, errors.New("missing required field 'maxFeeInFeeCurrency' in transaction")
}
itx.MaxFeeInFeeCurrency = (*big.Int)(dec.MaxFeeInFeeCurrency)
default:
return false, nil
Expand Down
Loading

0 comments on commit 2a94ad3

Please sign in to comment.