-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(primitives/types): related to tx payment module
- Loading branch information
Showing
10 changed files
with
172 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,71 @@ | ||
package types | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"testing" | ||
|
||
sc "github.com/LimeChain/goscale" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
expectedFeeDetailsBytes, _ = hex.DecodeString( | ||
"01010000000000000000000000000000000200000000000000000000000000000003000000000000000000000000000000", | ||
) | ||
) | ||
|
||
var ( | ||
targetFeeDetails = FeeDetails{ | ||
InclusionFee: sc.NewOption[InclusionFee](InclusionFee{ | ||
BaseFee: sc.NewU128(1), | ||
LenFee: sc.NewU128(2), | ||
AdjustedWeightFee: sc.NewU128(3), | ||
}), | ||
Tip: sc.NewU128(4), | ||
} | ||
) | ||
|
||
func Test_FeeDetails_Encode(t *testing.T) { | ||
buffer := &bytes.Buffer{} | ||
|
||
targetFeeDetails.Encode(buffer) | ||
|
||
assert.Equal(t, expectedFeeDetailsBytes, buffer.Bytes()) | ||
|
||
} | ||
|
||
func Test_FeeDetails_Bytes(t *testing.T) { | ||
assert.Equal(t, expectedFeeDetailsBytes, targetFeeDetails.Bytes()) | ||
} | ||
|
||
func Test_FeeDetails_DecodeFeeDetails(t *testing.T) { | ||
result := DecodeFeeDetails(bytes.NewBuffer(expectedFeeDetailsBytes)) | ||
|
||
expectedFeeDetails := FeeDetails{ | ||
InclusionFee: sc.NewOption[InclusionFee](InclusionFee{ | ||
BaseFee: sc.NewU128(1), | ||
LenFee: sc.NewU128(2), | ||
AdjustedWeightFee: sc.NewU128(3), | ||
}), | ||
} | ||
|
||
assert.Equal(t, expectedFeeDetails, result) | ||
} | ||
|
||
func Test_FeeDetails_FinalFee_WithInclusionFee(t *testing.T) { | ||
result := targetFeeDetails.FinalFee() | ||
|
||
assert.Equal(t, sc.NewU128(10), result) | ||
} | ||
|
||
func Test_FeeDetails_FinalFee_WithoutInclusionFee(t *testing.T) { | ||
targetFeeDetails := FeeDetails{ | ||
InclusionFee: sc.NewOption[InclusionFee](nil), | ||
Tip: sc.NewU128(4), | ||
} | ||
|
||
result := targetFeeDetails.FinalFee() | ||
|
||
assert.Equal(t, sc.NewU128(4), result) | ||
} |
This file contains 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 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,54 @@ | ||
package types | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"testing" | ||
|
||
sc "github.com/LimeChain/goscale" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
expectedInclusionFeeBytes, _ = hex.DecodeString( | ||
"010000000000000000000000000000000200000000000000000000000000000003000000000000000000000000000000", | ||
) | ||
) | ||
|
||
var ( | ||
targetInclusionFee = InclusionFee{ | ||
BaseFee: sc.NewU128(1), | ||
LenFee: sc.NewU128(2), | ||
AdjustedWeightFee: sc.NewU128(3), | ||
} | ||
) | ||
|
||
func Test_NewInclusionFee(t *testing.T) { | ||
result := NewInclusionFee(sc.NewU128(1), sc.NewU128(2), sc.NewU128(3)) | ||
|
||
assert.Equal(t, targetInclusionFee, result) | ||
} | ||
|
||
func Test_InclusionFee_Encode(t *testing.T) { | ||
buffer := &bytes.Buffer{} | ||
|
||
targetInclusionFee.Encode(buffer) | ||
|
||
assert.Equal(t, expectedInclusionFeeBytes, buffer.Bytes()) | ||
} | ||
|
||
func Test_InclusionFee_Bytes(t *testing.T) { | ||
assert.Equal(t, expectedInclusionFeeBytes, targetInclusionFee.Bytes()) | ||
} | ||
|
||
func Test_DecodeInclusionFee(t *testing.T) { | ||
result := DecodeInclusionFee(bytes.NewBuffer(expectedInclusionFeeBytes)) | ||
|
||
assert.Equal(t, targetInclusionFee, result) | ||
} | ||
|
||
func Test_InclusionFee_InclusionFee(t *testing.T) { | ||
result := targetInclusionFee.InclusionFee() | ||
|
||
assert.Equal(t, sc.NewU128(6), result) | ||
} |
This file contains 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 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