Skip to content

Commit

Permalink
public the extra limit size function
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed Nov 8, 2023
1 parent 186a9fd commit f177f8e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions common/extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ func TestTransactionExtraLimit(t *testing.T) {
require.Nil(err)
require.Equal(TxVersionHashSignature, int(ver.Version))
require.Equal(CM, hex.EncodeToString(ver.Marshal()))
require.Equal(ExtraSizeGeneralLimit, ver.getExtraLimit())
require.Equal(ExtraSizeGeneralLimit, ver.GetExtraLimit())

ver.Outputs[1].Amount = NewIntegerFromString("0.001")
require.Equal(ExtraSizeGeneralLimit, ver.getExtraLimit())
require.Equal(ExtraSizeGeneralLimit, ver.GetExtraLimit())
ver.Outputs[1].Script = NewThresholdScript(64)
require.Equal(ExtraSizeGeneralLimit, ver.getExtraLimit())
require.Equal(ExtraSizeGeneralLimit, ver.GetExtraLimit())

ver, _ = UnmarshalVersionedTransaction(cm)
ver.Outputs[0].Amount = NewIntegerFromString("0.001")
require.Equal(ExtraSizeGeneralLimit, ver.getExtraLimit())
require.Equal(ExtraSizeGeneralLimit, ver.GetExtraLimit())
ver.Outputs[0].Script = NewThresholdScript(64)
require.Equal(ExtraSizeGeneralLimit, ver.getExtraLimit())
require.Equal(ExtraSizeGeneralLimit, ver.GetExtraLimit())
ver.Outputs[0].Script = NewThresholdScript(63)
ver.Outputs[0].Keys = []*crypto.Key{&accounts[2].PublicSpendKey}
require.Equal(ExtraSizeGeneralLimit, ver.getExtraLimit())
require.Equal(ExtraSizeGeneralLimit, ver.GetExtraLimit())

ver.Extra = bytes.Repeat([]byte{0}, 257)
aas := make([][]*Address, len(ver.Inputs))
Expand All @@ -61,17 +61,17 @@ func TestTransactionExtraLimit(t *testing.T) {
require.Contains(err.Error(), "invalid extra size 257")

ver.Outputs[0].Script = NewThresholdScript(64)
require.Equal(ExtraSizeStorageStep, ver.getExtraLimit())
require.Equal(ExtraSizeStorageStep, ver.GetExtraLimit())
ver.Outputs[0].Amount = NewIntegerFromString("0.0015")
require.Equal(ExtraSizeStorageStep, ver.getExtraLimit())
require.Equal(ExtraSizeStorageStep, ver.GetExtraLimit())
ver.Outputs[0].Amount = NewIntegerFromString("0.0155")
require.Equal(ExtraSizeStorageStep*15, ver.getExtraLimit())
require.Equal(ExtraSizeStorageStep*15, ver.GetExtraLimit())
ver.Outputs[0].Amount = NewIntegerFromString("4.0959")
require.Equal(ExtraSizeStorageStep*4095, ver.getExtraLimit())
require.Equal(ExtraSizeStorageStep*4095, ver.GetExtraLimit())
ver.Outputs[0].Amount = NewIntegerFromString("4.0969")
require.Equal(ExtraSizeStorageStep*4096, ver.getExtraLimit())
require.Equal(ExtraSizeStorageStep*4096, ver.GetExtraLimit())
ver.Outputs[0].Amount = NewIntegerFromString("40.969")
require.Equal(ExtraSizeStorageStep*4096, ver.getExtraLimit())
require.Equal(ExtraSizeStorageStep*4096, ver.GetExtraLimit())

ver.Outputs[1].Amount = NewIntegerFromString("20000").Sub(NewIntegerFromString("40.969"))
ver.Extra = bytes.Repeat([]byte{0}, ExtraSizeStorageStep*4096-772)
Expand Down
4 changes: 2 additions & 2 deletions common/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (ver *VersionedTransaction) Validate(store DataStore, snapTime uint64, fork
return fmt.Errorf("invalid tx inputs or outputs %d %d %d",
len(tx.Inputs), len(tx.Outputs), len(tx.References))
}
if len(tx.Extra) > tx.getExtraLimit() {
if len(tx.Extra) > tx.GetExtraLimit() {
return fmt.Errorf("invalid extra size %d", len(tx.Extra))
}
if len(ver.PayloadMarshal()) > config.TransactionMaximumSize {
Expand Down Expand Up @@ -92,7 +92,7 @@ func (ver *VersionedTransaction) Validate(store DataStore, snapTime uint64, fork
return fmt.Errorf("invalid transaction type %d", txType)
}

func (tx *SignedTransaction) getExtraLimit() int {
func (tx *SignedTransaction) GetExtraLimit() int {
if tx.Version < TxVersionHashSignature {
panic(tx.Version)
}
Expand Down

0 comments on commit f177f8e

Please sign in to comment.