diff --git a/types/account_data.go b/types/account_data.go index 4e7b59700..a9c53fe04 100644 --- a/types/account_data.go +++ b/types/account_data.go @@ -22,7 +22,7 @@ type AccountInfo struct { Consumers U32 Providers U32 Sufficients U32 - Data struct { + Data struct { Free U128 Reserved U128 MiscFrozen U128 diff --git a/types/dispatch_result_with_post_info.go b/types/dispatch_result_with_post_info.go index ed9361a4e..6b2aeb0d4 100644 --- a/types/dispatch_result_with_post_info.go +++ b/types/dispatch_result_with_post_info.go @@ -21,7 +21,7 @@ import "github.com/centrifuge/go-substrate-rpc-client/v4/scale" // PostDispatchInfo is used in DispatchResultWithPostInfo. // Weight information that is only available post dispatch. type PostDispatchInfo struct { - ActualWeight OptionWeight + ActualWeight Option[Weight] PaysFee Pays } diff --git a/types/dispatch_result_with_post_info_test.go b/types/dispatch_result_with_post_info_test.go index f89974d09..4323c477e 100644 --- a/types/dispatch_result_with_post_info_test.go +++ b/types/dispatch_result_with_post_info_test.go @@ -29,7 +29,7 @@ var ( testDispatchResultWithPostInfo1 = DispatchResultWithPostInfo{ IsOk: true, Ok: PostDispatchInfo{ - ActualWeight: NewOptionWeight(123), + ActualWeight: NewOption(testWeight), PaysFee: Pays{ IsYes: true, }, @@ -39,7 +39,7 @@ var ( IsError: true, Error: DispatchErrorWithPostInfo{ PostInfo: PostDispatchInfo{ - ActualWeight: NewOptionWeight(456), + ActualWeight: NewOption(testWeight), PaysFee: Pays{ IsNo: true, }, @@ -51,7 +51,7 @@ var ( } dispatchResultWithPostInfoFuzzOpts = CombineFuzzOpts( - optionWeightFuzzOpts, + optionFuzzOpts, paysFuzzOpts, dispatchErrorFuzzOpts, []FuzzOpt{ @@ -77,14 +77,14 @@ func TestDispatchResultWithPostInfo_EncodeDecode(t *testing.T) { func TestDispatchResultWithPostInfo_Encode(t *testing.T) { AssertEncode(t, []EncodingAssert{ - {testDispatchResultWithPostInfo1, MustHexDecodeString("0x00017b0000000000000000")}, - {testDispatchResultWithPostInfo2, MustHexDecodeString("0x0101c8010000000000000100")}, + {testDispatchResultWithPostInfo1, MustHexDecodeString("0x00012ce90900")}, + {testDispatchResultWithPostInfo2, MustHexDecodeString("0x01012ce9090100")}, }) } func TestDispatchResultWithPostInfo_Decode(t *testing.T) { AssertDecode(t, []DecodingAssert{ - {MustHexDecodeString("0x00017b0000000000000000"), testDispatchResultWithPostInfo1}, - {MustHexDecodeString("0x0101c8010000000000000100"), testDispatchResultWithPostInfo2}, + {MustHexDecodeString("0x00012ce90900"), testDispatchResultWithPostInfo1}, + {MustHexDecodeString("0x01012ce9090100"), testDispatchResultWithPostInfo2}, }) } diff --git a/types/event_record_test.go b/types/event_record_test.go index a23d53d78..773f5bae1 100644 --- a/types/event_record_test.go +++ b/types/event_record_test.go @@ -41,21 +41,21 @@ var examplePhaseFin = Phase{ var exampleEventApp = EventSystemExtrinsicSuccess{ Phase: examplePhaseApp, - DispatchInfo: DispatchInfo{Weight: 10000, Class: DispatchClass{IsNormal: true}, PaysFee: Pays{IsYes: true}}, + DispatchInfo: DispatchInfo{Weight: testWeight, Class: DispatchClass{IsNormal: true}, PaysFee: Pays{IsYes: true}}, Topics: []Hash{{1, 2}}, } var exampleEventFin = EventSystemExtrinsicSuccess{ Phase: examplePhaseFin, - DispatchInfo: DispatchInfo{Weight: 10000, Class: DispatchClass{IsNormal: true}, PaysFee: Pays{IsYes: true}}, + DispatchInfo: DispatchInfo{Weight: testWeight, Class: DispatchClass{IsNormal: true}, PaysFee: Pays{IsYes: true}}, Topics: []Hash{{1, 2}}, } -var exampleEventAppEnc = []byte{0x0, 0x2a, 0x0, 0x0, 0x0, 0x10, 0x27, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x1, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} //nolint:lll +var exampleEventAppEnc = []byte{0x0, 0x2a, 0x0, 0x0, 0x0, 0x2c, 0xe9, 0x9, 0x0, 0x0, 0x4, 0x1, 0x2, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} //nolint:lll -var exampleEventFinEnc = []byte{0x1, 0x10, 0x27, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x1, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} //nolint:lll +var exampleEventFinEnc = []byte{0x1, 0x2c, 0xe9, 0x9, 0x0, 0x0, 0x4, 0x1, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} //nolint:lll var ( eventSystemExtrinsicSuccessFuzzOpts = CombineFuzzOpts( @@ -67,7 +67,7 @@ var ( func TestEventSystemExtrinsicSuccess_EncodeDecode(t *testing.T) { AssertRoundTripFuzz[EventSystemExtrinsicSuccess](t, 100, eventSystemExtrinsicSuccessFuzzOpts...) AssertDecodeNilData[EventSystemExtrinsicSuccess](t) - AssertEncodeEmptyObj[EventSystemExtrinsicSuccess](t, 9) + AssertEncodeEmptyObj[EventSystemExtrinsicSuccess](t, 3) } func TestEventSystemExtrinsicSuccess_Encode(t *testing.T) { @@ -135,13 +135,13 @@ func ExampleEventRecordsRaw_Decode() { "0x10" + "0000000000" + "0000" + - "1027000000000000" + // Weight + "2ce909" + // Weight "01" + // Operational "01" + // PaysFee "00" + "0001000000" + "0000" + - "1027000000000000" + // Weight + "2ce909" + // Weight "01" + // operational "01" + // PaysFee "00" + @@ -154,7 +154,7 @@ func ExampleEventRecordsRaw_Decode() { "0002000000" + "0000" + - "1027000000000000" + // Weight + "2ce909" + // Weight "00" + // Normal "01" + // PaysFee "00", @@ -244,14 +244,14 @@ func TestEventRecordsRaw_Decode(t *testing.T) { "0000000000" + // ApplyExtrinsic(0) "0000" + // System_ExtrinsicSuccess - "1027000000000000" + // Weight + "2ce909" + // Weight "01" + // DispatchClass: Operational "00" + // PaysFees "00" + // Topics "0001000000" + // ApplyExtrinsic(1) "0000" + // System_ExtrinsicSuccess - "1027000000000000" + // Weight + "2ce909" + // Weight "00" + // DispatchClass: Normal "00" + // PaysFees "00" + // Topics @@ -261,7 +261,7 @@ func TestEventRecordsRaw_Decode(t *testing.T) { "03" + // HasModule "0b" + // Module "01020304" + // Error - "1027000000000000" + // Weight + "2ce909" + // Weight "01" + // DispatchClass: Operational "00" + // PaysFees "00" + // Topics @@ -311,7 +311,7 @@ func TestEventRecordsRaw_Decode(t *testing.T) { Balances_ReserveRepatriated: []EventBalancesReserveRepatriated(nil), Grandpa_NewAuthorities: []EventGrandpaNewAuthorities(nil), Grandpa_Paused: []EventGrandpaPaused(nil), - Grandpa_Resumed: []EventGrandpaResumed(nil), ImOnline_HeartbeatReceived: []EventImOnlineHeartbeatReceived(nil), ImOnline_AllGood: []EventImOnlineAllGood(nil), ImOnline_SomeOffline: []EventImOnlineSomeOffline(nil), Indices_IndexAssigned: []EventIndicesIndexAssigned{EventIndicesIndexAssigned{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, AccountID: AccountID{0x8e, 0xaf, 0x4, 0x15, 0x16, 0x87, 0x73, 0x63, 0x26, 0xc9, 0xfe, 0xa1, 0x7e, 0x25, 0xfc, 0x52, 0x87, 0x61, 0x36, 0x93, 0xc9, 0x12, 0x90, 0x9c, 0xb2, 0x26, 0xaa, 0x47, 0x94, 0xf2, 0x6a, 0x48}, AccountIndex: 0x3039, Topics: []Hash(nil)}}, Indices_IndexFreed: []EventIndicesIndexFreed{EventIndicesIndexFreed{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, AccountIndex: 0x3039, Topics: []Hash(nil)}}, Indices_IndexFrozen: []EventIndicesIndexFrozen(nil), Offences_Offence: []EventOffencesOffence{EventOffencesOffence{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, Kind: Bytes16{0x69, 0x6d, 0x2d, 0x6f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x3a, 0x6f, 0x66, 0x66, 0x6c, 0x69, 0x6e}, OpaqueTimeSlot: Bytes{0xc5, 0x0, 0x0, 0x0}, Topics: []Hash(nil)}}, Session_NewSession: []EventSessionNewSession{EventSessionNewSession{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, SessionIndex: 0xc6, Topics: []Hash(nil)}}, Staking_EraPaid: []EventStakingEraPaid{EventStakingEraPaid{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, EraIndex: 0xc6, ValidatorPayout: NewU128(*big.NewInt(4586363775847)), Remainder: NewU128(*big.NewInt(0)), Topics: []Hash(nil)}}, Staking_Rewarded: []EventStakingRewarded(nil), Staking_Slashed: []EventStakingSlashed(nil), Staking_OldSlashingReportDiscarded: []EventStakingOldSlashingReportDiscarded(nil), Staking_StakersElected: []EventStakingStakersElected(nil), Staking_Bonded: []EventStakingBonded(nil), Staking_Unbonded: []EventStakingUnbonded(nil), Staking_Withdrawn: []EventStakingWithdrawn(nil), System_ExtrinsicSuccess: []EventSystemExtrinsicSuccess{EventSystemExtrinsicSuccess{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, DispatchInfo: DispatchInfo{Weight: 0x2710, Class: DispatchClass{IsNormal: false, IsOperational: true}, PaysFee: Pays{IsYes: true}}, Topics: []Hash(nil)}, EventSystemExtrinsicSuccess{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x1, IsFinalization: false}, DispatchInfo: DispatchInfo{Weight: 0x2710, Class: DispatchClass{IsNormal: true, IsOperational: false}, PaysFee: Pays{IsYes: true}}, Topics: []Hash(nil)}}, System_ExtrinsicFailed: []EventSystemExtrinsicFailed{EventSystemExtrinsicFailed{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x2, IsFinalization: false}, DispatchError: DispatchError{IsModule: true, ModuleError: ModuleError{Index: 0xb, Error: [4]U8{1, 2, 3, 4}}}, DispatchInfo: DispatchInfo{Weight: 0x2710, Class: DispatchClass{IsNormal: false, IsOperational: true}, PaysFee: Pays{IsYes: true}}, Topics: []Hash(nil)}}, System_CodeUpdated: []EventSystemCodeUpdated{EventSystemCodeUpdated{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, Topics: []Hash(nil)}}, System_NewAccount: []EventSystemNewAccount{EventSystemNewAccount{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, Who: AccountID{0x8e, 0xaf, 0x4, 0x15, 0x16, 0x87, 0x73, 0x63, 0x26, 0xc9, 0xfe, 0xa1, 0x7e, 0x25, 0xfc, 0x52, 0x87, 0x61, 0x36, 0x93, 0xc9, 0x12, 0x90, 0x9c, 0xb2, 0x26, 0xaa, 0x47, 0x94, 0xf2, 0x6a, 0x48}, Topics: []Hash(nil)}}, System_KilledAccount: []EventSystemKilledAccount{EventSystemKilledAccount{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, Who: AccountID{0x8e, 0xaf, 0x4, 0x15, 0x16, 0x87, 0x73, 0x63, 0x26, 0xc9, 0xfe, 0xa1, 0x7e, 0x25, 0xfc, 0x52, 0x87, 0x61, 0x36, 0x93, 0xc9, 0x12, 0x90, 0x9c, 0xb2, 0x26, 0xaa, 0x47, 0x94, 0xf2, 0x6a, 0x48}, Topics: []Hash(nil)}}, Assets_Issued: []EventAssetIssued(nil), Assets_Transferred: []EventAssetTransferred(nil), Assets_Destroyed: []EventAssetDestroyed(nil), Democracy_Proposed: []EventDemocracyProposed(nil), Democracy_Tabled: []EventDemocracyTabled(nil), Democracy_ExternalTabled: []EventDemocracyExternalTabled(nil), Democracy_Started: []EventDemocracyStarted(nil), Democracy_Passed: []EventDemocracyPassed(nil), Democracy_NotPassed: []EventDemocracyNotPassed(nil), Democracy_Cancelled: []EventDemocracyCancelled(nil), Democracy_Executed: []EventDemocracyExecuted(nil), Democracy_Delegated: []EventDemocracyDelegated(nil), Democracy_Undelegated: []EventDemocracyUndelegated(nil), Democracy_Vetoed: []EventDemocracyVetoed(nil), Democracy_PreimageNoted: []EventDemocracyPreimageNoted(nil), Democracy_PreimageUsed: []EventDemocracyPreimageUsed(nil), Democracy_PreimageInvalid: []EventDemocracyPreimageInvalid(nil), Democracy_PreimageMissing: []EventDemocracyPreimageMissing(nil), Democracy_PreimageReaped: []EventDemocracyPreimageReaped(nil), Council_Proposed: []EventCouncilProposed(nil), Council_Voted: []EventCouncilVoted(nil), Council_Approved: []EventCouncilApproved(nil), Council_Disapproved: []EventCouncilDisapproved(nil), Council_Executed: []EventCouncilExecuted(nil), Council_MemberExecuted: []EventCouncilMemberExecuted(nil), Council_Closed: []EventCouncilClosed(nil), TechnicalCommittee_Proposed: []EventTechnicalCommitteeProposed(nil), TechnicalCommittee_Voted: []EventTechnicalCommitteeVoted(nil), TechnicalCommittee_Approved: []EventTechnicalCommitteeApproved(nil), TechnicalCommittee_Disapproved: []EventTechnicalCommitteeDisapproved(nil), TechnicalCommittee_Executed: []EventTechnicalCommitteeExecuted(nil), TechnicalCommittee_MemberExecuted: []EventTechnicalCommitteeMemberExecuted(nil), TechnicalCommittee_Closed: []EventTechnicalCommitteeClosed(nil), Elections_NewTerm: []EventElectionsNewTerm(nil), Elections_EmptyTerm: []EventElectionsEmptyTerm(nil), Elections_MemberKicked: []EventElectionsMemberKicked(nil), Elections_Renounced: []EventElectionsRenounced(nil), Identity_IdentitySet: []EventIdentitySet(nil), Identity_IdentityCleared: []EventIdentityCleared(nil), Identity_IdentityKilled: []EventIdentityKilled(nil), Identity_JudgementRequested: []EventIdentityJudgementRequested(nil), Identity_JudgementUnrequested: []EventIdentityJudgementUnrequested(nil), Identity_JudgementGiven: []EventIdentityJudgementGiven(nil), Identity_RegistrarAdded: []EventIdentityRegistrarAdded(nil), Identity_SubIdentityAdded: []EventIdentitySubIdentityAdded(nil), Identity_SubIdentityRemoved: []EventIdentitySubIdentityRemoved(nil), Identity_SubIdentityRevoked: []EventIdentitySubIdentityRevoked(nil), Society_Founded: []EventSocietyFounded(nil), Society_Bid: []EventSocietyBid(nil), Society_Vouch: []EventSocietyVouch(nil), Society_AutoUnbid: []EventSocietyAutoUnbid(nil), Society_Unbid: []EventSocietyUnbid(nil), Society_Unvouch: []EventSocietyUnvouch(nil), Society_Inducted: []EventSocietyInducted(nil), Society_SuspendedMemberJudgement: []EventSocietySuspendedMemberJudgement(nil), Society_CandidateSuspended: []EventSocietyCandidateSuspended(nil), Society_MemberSuspended: []EventSocietyMemberSuspended(nil), Society_Challenged: []EventSocietyChallenged(nil), Society_Vote: []EventSocietyVote(nil), Society_DefenderVote: []EventSocietyDefenderVote(nil), Society_NewMaxMembers: []EventSocietyNewMaxMembers(nil), Society_Unfounded: []EventSocietyUnfounded(nil), Society_Deposit: []EventSocietyDeposit(nil), Recovery_RecoveryCreated: []EventRecoveryCreated(nil), Recovery_RecoveryInitiated: []EventRecoveryInitiated(nil), Recovery_RecoveryVouched: []EventRecoveryVouched(nil), Recovery_RecoveryClosed: []EventRecoveryClosed(nil), Recovery_AccountRecovered: []EventRecoveryAccountRecovered(nil), Recovery_RecoveryRemoved: []EventRecoveryRemoved(nil), Vesting_VestingUpdated: []EventVestingVestingUpdated(nil), Vesting_VestingCompleted: []EventVestingVestingCompleted(nil), Scheduler_Scheduled: []EventSchedulerScheduled(nil), Scheduler_Canceled: []EventSchedulerCanceled(nil), Scheduler_Dispatched: []EventSchedulerDispatched(nil), Proxy_ProxyExecuted: []EventProxyProxyExecuted(nil), Proxy_AnonymousCreated: []EventProxyAnonymousCreated(nil), Sudo_Sudid: []EventSudoSudid(nil), Sudo_KeyChanged: []EventSudoKeyChanged(nil), Sudo_SudoAsDone: []EventSudoAsDone(nil), Treasury_Proposed: []EventTreasuryProposed(nil), Treasury_Spending: []EventTreasurySpending(nil), Treasury_Awarded: []EventTreasuryAwarded(nil), Treasury_Rejected: []EventTreasuryRejected(nil), Treasury_Burnt: []EventTreasuryBurnt(nil), Treasury_Rollover: []EventTreasuryRollover(nil), Treasury_Deposit: []EventTreasuryDeposit(nil), Tips_NewTip: []EventTipsNewTip(nil), Tips_TipClosing: []EventTipsTipClosing(nil), Tips_TipClosed: []EventTipsTipClosed(nil), Tips_TipRetracted: []EventTipsTipRetracted(nil), Contracts_Instantiated: []EventContractsInstantiated(nil), Contracts_ContractEmitted: []EventContractsContractEmitted(nil), Contracts_ContractCodeUpdated: []EventContractsContractCodeUpdated(nil), Contracts_CodeStored: []EventContractsCodeStored(nil), Utility_BatchInterrupted: []EventUtilityBatchInterrupted(nil), Utility_BatchCompleted: []EventUtilityBatchCompleted(nil), Multisig_NewMultisig: []EventMultisigNewMultisig(nil), Multisig_MultisigApproval: []EventMultisigApproval(nil), Multisig_MultisigExecuted: []EventMultisigExecuted(nil), Multisig_MultisigCancelled: []EventMultisigCancelled(nil)} + Grandpa_Resumed: []EventGrandpaResumed(nil), ImOnline_HeartbeatReceived: []EventImOnlineHeartbeatReceived(nil), ImOnline_AllGood: []EventImOnlineAllGood(nil), ImOnline_SomeOffline: []EventImOnlineSomeOffline(nil), Indices_IndexAssigned: []EventIndicesIndexAssigned{EventIndicesIndexAssigned{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, AccountID: AccountID{0x8e, 0xaf, 0x4, 0x15, 0x16, 0x87, 0x73, 0x63, 0x26, 0xc9, 0xfe, 0xa1, 0x7e, 0x25, 0xfc, 0x52, 0x87, 0x61, 0x36, 0x93, 0xc9, 0x12, 0x90, 0x9c, 0xb2, 0x26, 0xaa, 0x47, 0x94, 0xf2, 0x6a, 0x48}, AccountIndex: 0x3039, Topics: []Hash(nil)}}, Indices_IndexFreed: []EventIndicesIndexFreed{EventIndicesIndexFreed{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, AccountIndex: 0x3039, Topics: []Hash(nil)}}, Indices_IndexFrozen: []EventIndicesIndexFrozen(nil), Offences_Offence: []EventOffencesOffence{EventOffencesOffence{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, Kind: Bytes16{0x69, 0x6d, 0x2d, 0x6f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x3a, 0x6f, 0x66, 0x66, 0x6c, 0x69, 0x6e}, OpaqueTimeSlot: Bytes{0xc5, 0x0, 0x0, 0x0}, Topics: []Hash(nil)}}, Session_NewSession: []EventSessionNewSession{EventSessionNewSession{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, SessionIndex: 0xc6, Topics: []Hash(nil)}}, Staking_EraPaid: []EventStakingEraPaid{EventStakingEraPaid{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, EraIndex: 0xc6, ValidatorPayout: NewU128(*big.NewInt(4586363775847)), Remainder: NewU128(*big.NewInt(0)), Topics: []Hash(nil)}}, Staking_Rewarded: []EventStakingRewarded(nil), Staking_Slashed: []EventStakingSlashed(nil), Staking_OldSlashingReportDiscarded: []EventStakingOldSlashingReportDiscarded(nil), Staking_StakersElected: []EventStakingStakersElected(nil), Staking_Bonded: []EventStakingBonded(nil), Staking_Unbonded: []EventStakingUnbonded(nil), Staking_Withdrawn: []EventStakingWithdrawn(nil), System_ExtrinsicSuccess: []EventSystemExtrinsicSuccess{EventSystemExtrinsicSuccess{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, DispatchInfo: DispatchInfo{Weight: testWeight, Class: DispatchClass{IsNormal: false, IsOperational: true}, PaysFee: Pays{IsYes: true}}, Topics: []Hash(nil)}, EventSystemExtrinsicSuccess{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x1, IsFinalization: false}, DispatchInfo: DispatchInfo{Weight: testWeight, Class: DispatchClass{IsNormal: true, IsOperational: false}, PaysFee: Pays{IsYes: true}}, Topics: []Hash(nil)}}, System_ExtrinsicFailed: []EventSystemExtrinsicFailed{EventSystemExtrinsicFailed{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x2, IsFinalization: false}, DispatchError: DispatchError{IsModule: true, ModuleError: ModuleError{Index: 0xb, Error: [4]U8{1, 2, 3, 4}}}, DispatchInfo: DispatchInfo{Weight: testWeight, Class: DispatchClass{IsNormal: false, IsOperational: true}, PaysFee: Pays{IsYes: true}}, Topics: []Hash(nil)}}, System_CodeUpdated: []EventSystemCodeUpdated{EventSystemCodeUpdated{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, Topics: []Hash(nil)}}, System_NewAccount: []EventSystemNewAccount{EventSystemNewAccount{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, Who: AccountID{0x8e, 0xaf, 0x4, 0x15, 0x16, 0x87, 0x73, 0x63, 0x26, 0xc9, 0xfe, 0xa1, 0x7e, 0x25, 0xfc, 0x52, 0x87, 0x61, 0x36, 0x93, 0xc9, 0x12, 0x90, 0x9c, 0xb2, 0x26, 0xaa, 0x47, 0x94, 0xf2, 0x6a, 0x48}, Topics: []Hash(nil)}}, System_KilledAccount: []EventSystemKilledAccount{EventSystemKilledAccount{Phase: Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 0x0, IsFinalization: false}, Who: AccountID{0x8e, 0xaf, 0x4, 0x15, 0x16, 0x87, 0x73, 0x63, 0x26, 0xc9, 0xfe, 0xa1, 0x7e, 0x25, 0xfc, 0x52, 0x87, 0x61, 0x36, 0x93, 0xc9, 0x12, 0x90, 0x9c, 0xb2, 0x26, 0xaa, 0x47, 0x94, 0xf2, 0x6a, 0x48}, Topics: []Hash(nil)}}, Assets_Issued: []EventAssetIssued(nil), Assets_Transferred: []EventAssetTransferred(nil), Assets_Destroyed: []EventAssetDestroyed(nil), Democracy_Proposed: []EventDemocracyProposed(nil), Democracy_Tabled: []EventDemocracyTabled(nil), Democracy_ExternalTabled: []EventDemocracyExternalTabled(nil), Democracy_Started: []EventDemocracyStarted(nil), Democracy_Passed: []EventDemocracyPassed(nil), Democracy_NotPassed: []EventDemocracyNotPassed(nil), Democracy_Cancelled: []EventDemocracyCancelled(nil), Democracy_Executed: []EventDemocracyExecuted(nil), Democracy_Delegated: []EventDemocracyDelegated(nil), Democracy_Undelegated: []EventDemocracyUndelegated(nil), Democracy_Vetoed: []EventDemocracyVetoed(nil), Democracy_PreimageNoted: []EventDemocracyPreimageNoted(nil), Democracy_PreimageUsed: []EventDemocracyPreimageUsed(nil), Democracy_PreimageInvalid: []EventDemocracyPreimageInvalid(nil), Democracy_PreimageMissing: []EventDemocracyPreimageMissing(nil), Democracy_PreimageReaped: []EventDemocracyPreimageReaped(nil), Council_Proposed: []EventCouncilProposed(nil), Council_Voted: []EventCouncilVoted(nil), Council_Approved: []EventCouncilApproved(nil), Council_Disapproved: []EventCouncilDisapproved(nil), Council_Executed: []EventCouncilExecuted(nil), Council_MemberExecuted: []EventCouncilMemberExecuted(nil), Council_Closed: []EventCouncilClosed(nil), TechnicalCommittee_Proposed: []EventTechnicalCommitteeProposed(nil), TechnicalCommittee_Voted: []EventTechnicalCommitteeVoted(nil), TechnicalCommittee_Approved: []EventTechnicalCommitteeApproved(nil), TechnicalCommittee_Disapproved: []EventTechnicalCommitteeDisapproved(nil), TechnicalCommittee_Executed: []EventTechnicalCommitteeExecuted(nil), TechnicalCommittee_MemberExecuted: []EventTechnicalCommitteeMemberExecuted(nil), TechnicalCommittee_Closed: []EventTechnicalCommitteeClosed(nil), Elections_NewTerm: []EventElectionsNewTerm(nil), Elections_EmptyTerm: []EventElectionsEmptyTerm(nil), Elections_MemberKicked: []EventElectionsMemberKicked(nil), Elections_Renounced: []EventElectionsRenounced(nil), Identity_IdentitySet: []EventIdentitySet(nil), Identity_IdentityCleared: []EventIdentityCleared(nil), Identity_IdentityKilled: []EventIdentityKilled(nil), Identity_JudgementRequested: []EventIdentityJudgementRequested(nil), Identity_JudgementUnrequested: []EventIdentityJudgementUnrequested(nil), Identity_JudgementGiven: []EventIdentityJudgementGiven(nil), Identity_RegistrarAdded: []EventIdentityRegistrarAdded(nil), Identity_SubIdentityAdded: []EventIdentitySubIdentityAdded(nil), Identity_SubIdentityRemoved: []EventIdentitySubIdentityRemoved(nil), Identity_SubIdentityRevoked: []EventIdentitySubIdentityRevoked(nil), Society_Founded: []EventSocietyFounded(nil), Society_Bid: []EventSocietyBid(nil), Society_Vouch: []EventSocietyVouch(nil), Society_AutoUnbid: []EventSocietyAutoUnbid(nil), Society_Unbid: []EventSocietyUnbid(nil), Society_Unvouch: []EventSocietyUnvouch(nil), Society_Inducted: []EventSocietyInducted(nil), Society_SuspendedMemberJudgement: []EventSocietySuspendedMemberJudgement(nil), Society_CandidateSuspended: []EventSocietyCandidateSuspended(nil), Society_MemberSuspended: []EventSocietyMemberSuspended(nil), Society_Challenged: []EventSocietyChallenged(nil), Society_Vote: []EventSocietyVote(nil), Society_DefenderVote: []EventSocietyDefenderVote(nil), Society_NewMaxMembers: []EventSocietyNewMaxMembers(nil), Society_Unfounded: []EventSocietyUnfounded(nil), Society_Deposit: []EventSocietyDeposit(nil), Recovery_RecoveryCreated: []EventRecoveryCreated(nil), Recovery_RecoveryInitiated: []EventRecoveryInitiated(nil), Recovery_RecoveryVouched: []EventRecoveryVouched(nil), Recovery_RecoveryClosed: []EventRecoveryClosed(nil), Recovery_AccountRecovered: []EventRecoveryAccountRecovered(nil), Recovery_RecoveryRemoved: []EventRecoveryRemoved(nil), Vesting_VestingUpdated: []EventVestingVestingUpdated(nil), Vesting_VestingCompleted: []EventVestingVestingCompleted(nil), Scheduler_Scheduled: []EventSchedulerScheduled(nil), Scheduler_Canceled: []EventSchedulerCanceled(nil), Scheduler_Dispatched: []EventSchedulerDispatched(nil), Proxy_ProxyExecuted: []EventProxyProxyExecuted(nil), Proxy_AnonymousCreated: []EventProxyAnonymousCreated(nil), Sudo_Sudid: []EventSudoSudid(nil), Sudo_KeyChanged: []EventSudoKeyChanged(nil), Sudo_SudoAsDone: []EventSudoAsDone(nil), Treasury_Proposed: []EventTreasuryProposed(nil), Treasury_Spending: []EventTreasurySpending(nil), Treasury_Awarded: []EventTreasuryAwarded(nil), Treasury_Rejected: []EventTreasuryRejected(nil), Treasury_Burnt: []EventTreasuryBurnt(nil), Treasury_Rollover: []EventTreasuryRollover(nil), Treasury_Deposit: []EventTreasuryDeposit(nil), Tips_NewTip: []EventTipsNewTip(nil), Tips_TipClosing: []EventTipsTipClosing(nil), Tips_TipClosed: []EventTipsTipClosed(nil), Tips_TipRetracted: []EventTipsTipRetracted(nil), Contracts_Instantiated: []EventContractsInstantiated(nil), Contracts_ContractEmitted: []EventContractsContractEmitted(nil), Contracts_ContractCodeUpdated: []EventContractsContractCodeUpdated(nil), Contracts_CodeStored: []EventContractsCodeStored(nil), Utility_BatchInterrupted: []EventUtilityBatchInterrupted(nil), Utility_BatchCompleted: []EventUtilityBatchCompleted(nil), Multisig_NewMultisig: []EventMultisigNewMultisig(nil), Multisig_MultisigApproval: []EventMultisigApproval(nil), Multisig_MultisigExecuted: []EventMultisigExecuted(nil), Multisig_MultisigCancelled: []EventMultisigCancelled(nil)} //nolint:lll assert.Equal(t, exp, events) diff --git a/types/events_test.go b/types/events_test.go index ea65189d5..d4cb5c20c 100644 --- a/types/events_test.go +++ b/types/events_test.go @@ -37,7 +37,7 @@ var ( func TestDispatchInfo_EncodeDecode(t *testing.T) { AssertRoundTripFuzz[DispatchInfo](t, 100, dispatchInfoFuzzOpts...) AssertDecodeNilData[DispatchInfo](t) - AssertEncodeEmptyObj[DispatchInfo](t, 8) + AssertEncodeEmptyObj[DispatchInfo](t, 2) } func TestVoteThreshold_Decoder(t *testing.T) { diff --git a/types/outcome_test.go b/types/outcome_test.go index d4f04fbd4..2ee962a05 100644 --- a/types/outcome_test.go +++ b/types/outcome_test.go @@ -28,11 +28,11 @@ import ( var ( testOutcome1 = Outcome{ IsComplete: true, - CompleteWeight: 123, + CompleteWeight: testWeight, } testOutcome2 = Outcome{ IsIncomplete: true, - IncompleteWeight: 54, + IncompleteWeight: testWeight, IncompleteError: XCMError{ IsOverflow: true, }, @@ -77,16 +77,16 @@ func TestOutcome_EncodeDecode(t *testing.T) { func TestOutcome_Encode(t *testing.T) { AssertEncode(t, []EncodingAssert{ - {testOutcome1, MustHexDecodeString("0x007b00000000000000")}, - {testOutcome2, MustHexDecodeString("0x01360000000000000000")}, + {testOutcome1, MustHexDecodeString("0x002ce909")}, + {testOutcome2, MustHexDecodeString("0x012ce90900")}, {testOutcome3, MustHexDecodeString("0x0201")}, }) } func TestOutcome_Decode(t *testing.T) { AssertDecode(t, []DecodingAssert{ - {MustHexDecodeString("0x007b00000000000000"), testOutcome1}, - {MustHexDecodeString("0x01360000000000000000"), testOutcome2}, + {MustHexDecodeString("0x002ce909"), testOutcome1}, + {MustHexDecodeString("0x012ce90900"), testOutcome2}, {MustHexDecodeString("0x0201"), testOutcome3}, }) } diff --git a/types/weight.go b/types/weight.go index c4dd104ab..0d46475a8 100644 --- a/types/weight.go +++ b/types/weight.go @@ -16,59 +16,18 @@ package types -import "github.com/centrifuge/go-substrate-rpc-client/v4/scale" - -type OptionWeight struct { - option - value Weight -} - // Weight is a numeric range of a transaction weight -type Weight uint64 - -// NewWeight creates a new Weight type -func NewWeight(u uint64) Weight { - return Weight(u) +type Weight struct { + // The weight of computational time used based on some reference hardware. + RefTime UCompact + // The weight of storage space used by proof of validity. + ProofSize UCompact } -func NewOptionWeight(value Weight) OptionWeight { - return OptionWeight{ - option: option{ - hasValue: true, - }, - value: value, - } -} - -func NewOptionWeightEmpty() OptionWeight { - return OptionWeight{ - option: option{ - hasValue: false, - }, +// NewWeight creates a new Weight type +func NewWeight(refTime UCompact, proofSize UCompact) Weight { + return Weight{ + RefTime: refTime, + ProofSize: proofSize, } } - -func (o OptionWeight) Encode(encoder scale.Encoder) error { - return encoder.EncodeOption(o.hasValue, o.value) -} - -func (o *OptionWeight) Decode(decoder scale.Decoder) error { - return decoder.DecodeOption(&o.hasValue, &o.value) -} - -// SetSome sets a value -func (o *OptionWeight) SetSome(value Weight) { - o.hasValue = true - o.value = value -} - -// SetNone removes a value and marks it as missing -func (o *OptionWeight) SetNone() { - o.hasValue = false - o.value = Weight(0) -} - -// Unwrap returns a flag that indicates whether a value is present and the stored value -func (o *OptionWeight) Unwrap() (ok bool, value Weight) { - return o.hasValue, o.value -} diff --git a/types/weight_test.go b/types/weight_test.go index 104f9de1f..f0e980bcd 100644 --- a/types/weight_test.go +++ b/types/weight_test.go @@ -22,102 +22,48 @@ import ( . "github.com/centrifuge/go-substrate-rpc-client/v4/types" . "github.com/centrifuge/go-substrate-rpc-client/v4/types/codec" . "github.com/centrifuge/go-substrate-rpc-client/v4/types/test_utils" - fuzz "github.com/google/gofuzz" - "github.com/stretchr/testify/assert" ) var ( - optionWeightFuzzOpts = []FuzzOpt{ - WithFuzzFuncs(func(o *OptionWeight, c fuzz.Continue) { - if c.RandBool() { - *o = NewOptionWeightEmpty() - return - } - - var weight Weight - - c.Fuzz(&weight) - - *o = NewOptionWeight(weight) - }), - } + testWeight = NewWeight(NewUCompactFromUInt(11), NewUCompactFromUInt(634)) ) -func TestOptionWeight_EncodeDecode(t *testing.T) { - AssertRoundTripFuzz[OptionWeight](t, 100, optionWeightFuzzOpts...) - AssertEncodeEmptyObj[OptionWeight](t, 1) -} - -func TestOptionWeight_Encode(t *testing.T) { - AssertEncode(t, []EncodingAssert{ - {NewOptionWeight(NewWeight(0)), MustHexDecodeString("0x010000000000000000")}, - {NewOptionWeight(NewWeight(1)), MustHexDecodeString("0x010100000000000000")}, - {NewOptionWeight(NewWeight(2)), MustHexDecodeString("0x010200000000000000")}, - {NewOptionWeightEmpty(), MustHexDecodeString("0x00")}, - }) -} - -func TestOptionWeight_Decode(t *testing.T) { - AssertDecode(t, []DecodingAssert{ - {MustHexDecodeString("0x010000000000000000"), NewOptionWeight(NewWeight(0))}, - {MustHexDecodeString("0x010100000000000000"), NewOptionWeight(NewWeight(1))}, - {MustHexDecodeString("0x010200000000000000"), NewOptionWeight(NewWeight(2))}, - {MustHexDecodeString("0x00"), NewOptionWeightEmpty()}, - }) -} - -func TestOptionWeight_OptionMethods(t *testing.T) { - o := NewOptionWeightEmpty() - o.SetSome(Weight(11)) - - ok, v := o.Unwrap() - assert.True(t, ok) - assert.NotNil(t, v) - - o.SetNone() - - ok, v = o.Unwrap() - assert.False(t, ok) - assert.Equal(t, Weight(0), v) -} - func TestWeight_EncodeDecode(t *testing.T) { AssertRoundTripFuzz[Weight](t, 100) - AssertDecodeNilData[Weight](t) - AssertEncodeEmptyObj[Weight](t, 8) + AssertEncodeEmptyObj[Weight](t, 2) } func TestWeight_EncodedLength(t *testing.T) { - AssertEncodedLength(t, []EncodedLengthAssert{{NewWeight(13), 8}}) + AssertEncodedLength(t, []EncodedLengthAssert{{testWeight, 3}}) } func TestWeight_Encode(t *testing.T) { AssertEncode(t, []EncodingAssert{ - {NewWeight(29), MustHexDecodeString("0x1d00000000000000")}, + {testWeight, MustHexDecodeString("0x2ce909")}, + }) +} + +func TestWeight_Decode(t *testing.T) { + AssertDecode(t, []DecodingAssert{ + {MustHexDecodeString("0x2ce909"), testWeight}, }) } func TestWeight_Hash(t *testing.T) { AssertHash(t, []HashAssert{ - {NewWeight(29), MustHexDecodeString("0x83e168a13a013e6d47b0778f046aaa05d6c01d6857d044d9e9b658a6d85eb865")}, + {testWeight, MustHexDecodeString("0x7daf57922bb9694b4e29da7634e1b0a6af1477a8d13b0544208cda78331ea135")}, }) } func TestWeight_Hex(t *testing.T) { AssertEncodeToHex(t, []EncodeToHexAssert{ - {NewWeight(29), "0x1d00000000000000"}, - }) -} - -func TestWeight_String(t *testing.T) { - AssertString(t, []StringAssert{ - {NewWeight(29), "29"}, + {testWeight, "0x2ce909"}, }) } func TestWeight_Eq(t *testing.T) { AssertEq(t, []EqAssert{ - {NewWeight(23), NewWeight(23), true}, - {NewWeight(23), NewBool(false), false}, + {testWeight, NewWeight(NewUCompactFromUInt(11), NewUCompactFromUInt(634)), true}, + {testWeight, NewBool(false), false}, }) }