Skip to content

Commit 10bf966

Browse files
committed
feat(power15): new CurrentTotalPowerReturn fields, add serialization tests
1 parent dbe511a commit 10bf966

File tree

3 files changed

+120
-2
lines changed

3 files changed

+120
-2
lines changed

builtin/v15/power/cbor_gen.go

Lines changed: 59 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builtin/v15/power/power_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ type CurrentTotalPowerReturn struct {
4747
QualityAdjPower abi.StoragePower
4848
PledgeCollateral abi.TokenAmount
4949
QualityAdjPowerSmoothed smoothing.FilterEstimate
50+
RampStartEpoch int64
51+
RampDurationEpochs uint64
5052
}
5153

5254
type NetworkRawPowerReturn = abi.StoragePower

builtin/v15/power/power_types_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package power
2+
3+
import (
4+
"bytes"
5+
"encoding/hex"
6+
"testing"
7+
8+
"github.com/filecoin-project/go-state-types/abi"
9+
"github.com/filecoin-project/go-state-types/big"
10+
"github.com/filecoin-project/go-state-types/builtin/v15/util/smoothing"
11+
"github.com/stretchr/testify/require"
12+
)
13+
14+
// Test to match with Rust fil_actor_power::serialization
15+
func TestSerializationCurrentTotalPowerReturn(t *testing.T) {
16+
testCases := []struct {
17+
params CurrentTotalPowerReturn
18+
hex string
19+
}{
20+
{
21+
params: CurrentTotalPowerReturn{
22+
RawBytePower: abi.NewStoragePower(0),
23+
QualityAdjPower: abi.NewStoragePower(0),
24+
PledgeCollateral: abi.NewTokenAmount(0),
25+
QualityAdjPowerSmoothed: smoothing.NewEstimate(big.Zero(), big.Zero()),
26+
RampStartEpoch: 0,
27+
RampDurationEpochs: 0,
28+
},
29+
// [byte[],byte[],byte[],[byte[],byte[]],0,0]
30+
hex: "864040408240400000",
31+
},
32+
{
33+
params: CurrentTotalPowerReturn{
34+
RawBytePower: abi.NewStoragePower(1 << 20),
35+
QualityAdjPower: abi.NewStoragePower(1 << 21),
36+
PledgeCollateral: abi.NewTokenAmount(1 << 22),
37+
QualityAdjPowerSmoothed: smoothing.NewEstimate(big.NewInt(1<<23), big.NewInt(1<<24)),
38+
RampStartEpoch: 25,
39+
RampDurationEpochs: 26,
40+
},
41+
// FilterEstimate BigInts have a precision shift of 128, so they end up larger than the others.
42+
// [byte[00100000],byte[00200000],byte[00400000],[byte[0080000000000000000000000000000000000000],byte[000100000000000000000000000000000000000000]],25,26]
43+
hex: "8644001000004400200000440040000082540080000000000000000000000000000000000000550001000000000000000000000000000000000000001819181a",
44+
},
45+
}
46+
47+
for _, tc := range testCases {
48+
t.Run("", func(t *testing.T) {
49+
req := require.New(t)
50+
51+
var buf bytes.Buffer
52+
req.NoError(tc.params.MarshalCBOR(&buf))
53+
req.Equal(tc.hex, hex.EncodeToString(buf.Bytes()))
54+
var rt CurrentTotalPowerReturn
55+
req.NoError(rt.UnmarshalCBOR(&buf))
56+
req.Equal(tc.params, rt)
57+
})
58+
}
59+
}

0 commit comments

Comments
 (0)