Skip to content

Commit

Permalink
lib: Drop old metadata examples, fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
cdamian committed Sep 10, 2024
1 parent 2e0b9c6 commit 9dfb473
Show file tree
Hide file tree
Showing 22 changed files with 11 additions and 615 deletions.
4 changes: 2 additions & 2 deletions registry/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package registry
import (
"bytes"
"fmt"
"github.com/centrifuge/go-substrate-rpc-client/v4/types/extrinsic"
"github.com/ethereum/go-ethereum/common/hexutil"

"github.com/centrifuge/go-substrate-rpc-client/v4/scale"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types/extrinsic"
"github.com/ethereum/go-ethereum/common/hexutil"
)

// FieldDecoder is the interface implemented by all the different types that are available.
Expand Down
3 changes: 2 additions & 1 deletion registry/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,8 @@ func (f *factory) getStoredFieldDecoder(fieldLookupIndex int64) (FieldDecoder, b
}

const (
// ExpectedExtrinsicParamsCount is the count of generic params that we expect for a generic Extrinsic type from the metadata.
// ExpectedExtrinsicParamsCount is the count of generic params that we expect for a
// generic Extrinsic type from the metadata.
//
// The parameters are expected to be in the following order:
// 1. Address
Expand Down
3 changes: 2 additions & 1 deletion registry/retriever/extrinsic_retriever.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package retriever

import (
"time"

"github.com/centrifuge/go-substrate-rpc-client/v4/registry"
"github.com/centrifuge/go-substrate-rpc-client/v4/registry/exec"
"github.com/centrifuge/go-substrate-rpc-client/v4/rpc/chain"
"github.com/centrifuge/go-substrate-rpc-client/v4/rpc/state"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types/block"
"time"
)

//nolint:lll
Expand Down
1 change: 1 addition & 0 deletions types/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package block

import (
"errors"

"github.com/centrifuge/go-substrate-rpc-client/v4/registry"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
)
Expand Down
13 changes: 0 additions & 13 deletions types/call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ func TestCall(t *testing.T) {
assert.Equal(t, "0x0601000000", enc)
}

func TestNewCallV4(t *testing.T) {
addr, err := NewAddressFromHexAccountID("0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48")
assert.NoError(t, err)

c, err := NewCall(ExamplaryMetadataV4, "balances.transfer", addr, NewUCompactFromUInt(1000))
assert.NoError(t, err)

enc, err := codec.EncodeToHex(c)
assert.NoError(t, err)

assert.Equal(t, "0x0300ff8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48a10f", enc)
}

func TestNewCallV7(t *testing.T) {
c, err := NewCall(&exampleMetadataV7, "Module2.my function", U8(3))
assert.NoError(t, err)
Expand Down
86 changes: 0 additions & 86 deletions types/event_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package types_test

import (
"fmt"
"testing"

. "github.com/centrifuge/go-substrate-rpc-client/v4/types"
Expand Down Expand Up @@ -89,91 +88,6 @@ func TestEventSystemExtrinsicSuccess_Decode(t *testing.T) {
assert.Equal(t, exampleEventApp, decoded)
}

func TestEventRecordsRaw_Decode_FailsNumFields(t *testing.T) {
e := EventRecordsRaw(MustHexDecodeString("0x0400020000000302d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48266d00000000000000000000000000000010a5d4e8000000000000000000000000")) //nolint:lll

events := struct {
Balances_Transfer []struct{ Abc uint8 } //nolint:stylecheck,golint
}{}
err := e.DecodeEventRecords(ExamplaryMetadataV8, &events)
assert.EqualError(t, err, "expected event #0 with EventID [3 2], field Balances_Transfer to have at least 2 fields (for Phase and Topics), but has 1 fields") //nolint:lll
}

func TestEventRecordsRaw_Decode_FailsFirstNotPhase(t *testing.T) {
e := EventRecordsRaw(MustHexDecodeString("0x0400020000000302d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48266d00000000000000000000000000000010a5d4e8000000000000000000000000")) //nolint:lll

events := struct {
Balances_Transfer []struct { //nolint:stylecheck,golint
P uint8
Other uint32
T []Hash
}
}{}
err := e.DecodeEventRecords(ExamplaryMetadataV8, &events)
assert.EqualError(t, err, "expected the first field of event #0 with EventID [3 2], field Balances_Transfer to be of type types.Phase, but got uint8") //nolint:lll
}

func TestEventRecordsRaw_Decode_FailsLastNotHash(t *testing.T) {
e := EventRecordsRaw(MustHexDecodeString("0x0400020000000302d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48266d00000000000000000000000000000010a5d4e8000000000000000000000000")) //nolint:lll

events := struct {
Balances_Transfer []struct { //nolint:stylecheck,golint
P Phase
Other uint32
T Phase
}
}{}
err := e.DecodeEventRecords(ExamplaryMetadataV8, &events)
assert.EqualError(t, err, "expected the last field of event #0 with EventID [3 2], field Balances_Transfer to be of type []types.Hash for Topics, but got types.Phase") //nolint:lll
}

func ExampleEventRecordsRaw_Decode() {
e := EventRecordsRaw(MustHexDecodeString(
"0x10" +
"0000000000" +
"0000" +
"2ce909" + // Weight
"01" + // Operational
"01" + // PaysFee
"00" +
"0001000000" +
"0000" +
"2ce909" + // Weight
"01" + // operational
"01" + // PaysFee
"00" +
"0001000000" + // ApplyExtrinsic(1)
"0302" + // Balances_Transfer
"d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" + // From
"8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48" + // To
"391b0000000000000000000000000000" + // Value
"00" + // Topics

"0002000000" +
"0000" +
"2ce909" + // Weight
"00" + // Normal
"01" + // PaysFee
"00",
))

events := EventRecords{}
err := e.DecodeEventRecords(ExamplaryMetadataV8, &events)
if err != nil {
panic(err)
}

fmt.Printf("Got %v System_ExtrinsicSuccess events\n", len(events.System_ExtrinsicSuccess))
fmt.Printf("Got %v Balances_Transfer events\n", len(events.Balances_Transfer))
t := events.Balances_Transfer[0]
fmt.Printf("Transfer: %v tokens from %#x to\n%#x", t.Value, t.From, t.To)

// Output: Got 3 System_ExtrinsicSuccess events
// Got 1 Balances_Transfer events
// Transfer: 6969 tokens from 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d to
// 0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48
}

func TestDispatchError(t *testing.T) {
AssertRoundTripFuzz[DispatchError](t, 1000, dispatchErrorFuzzOpts...)
AssertDecodeNilData[DispatchError](t)
Expand Down
4 changes: 3 additions & 1 deletion types/extrinsic/extrinsic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"bytes"
"encoding/json"
"fmt"
"math/big"

libErr "github.com/centrifuge/go-substrate-rpc-client/v4/error"
"github.com/centrifuge/go-substrate-rpc-client/v4/scale"
"github.com/centrifuge/go-substrate-rpc-client/v4/signature"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types/codec"
"math/big"
)

const (
Expand Down Expand Up @@ -78,6 +79,7 @@ func (e Extrinsic) Type() uint8 {
// Sign adds a signature to the extrinsic.
func (e *Extrinsic) Sign(signer signature.KeyringPair, meta *types.Metadata, opts ...SigningOption) error {
if e.Type() != Version4 {
//nolint:lll
return ErrInvalidVersion.WithMsg("unsupported extrinsic version: %v (isSigned: %v, type: %v)", e.Version, e.IsSigned(), e.Type())
}

Expand Down
29 changes: 0 additions & 29 deletions types/metadataV10_example.go

This file was deleted.

20 changes: 0 additions & 20 deletions types/metadataV11_example.go

This file was deleted.

21 changes: 0 additions & 21 deletions types/metadataV11_example_string.go

This file was deleted.

27 changes: 0 additions & 27 deletions types/metadataV11_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"

. "github.com/centrifuge/go-substrate-rpc-client/v4/types"
. "github.com/centrifuge/go-substrate-rpc-client/v4/types/codec"
"github.com/stretchr/testify/assert"
)

Expand All @@ -30,32 +29,6 @@ var exampleMetadataV11 = Metadata{
AsMetadataV11: MetadataV11{MetadataV10: exampleRuntimeMetadataV10},
}

func TestNewMetadataV11_Decode(t *testing.T) {
tests := []struct {
name, hexData string
}{
{
"SubstrateV11", ExamplaryMetadataV11SubstrateString,
},

{
"PolkadotV11", ExamplaryMetadataV11PolkadotString,
},
}

for _, s := range tests {
t.Run(s.name, func(t *testing.T) {
metadata := NewMetadataV11()
err := Decode(MustHexDecodeString(s.hexData), metadata)
assert.NoError(t, err)
data, err := Encode(metadata)
assert.NoError(t, err)
assert.Equal(t, s.hexData, HexEncodeToString(data))
})

}
}

func TestMetadataV11_ExistsModuleMetadata(t *testing.T) {
assert.True(t, exampleMetadataV11.ExistsModuleMetadata("EmptyModule"))
assert.False(t, exampleMetadataV11.ExistsModuleMetadata("NotExistModule"))
Expand Down
20 changes: 0 additions & 20 deletions types/metadataV12_example.go

This file was deleted.

24 changes: 0 additions & 24 deletions types/metadataV12_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"

. "github.com/centrifuge/go-substrate-rpc-client/v4/types"
. "github.com/centrifuge/go-substrate-rpc-client/v4/types/codec"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -79,29 +78,6 @@ var exampleModuleMetadataV122 = ModuleMetadataV12{
Index: 2,
}

func TestNewMetadataV12_Decode(t *testing.T) {
tests := []struct {
name, hexData string
}{
{
"PolkadotV12", ExamplaryMetadataV12PolkadotString,
},
}

for _, s := range tests {
t.Run(s.name, func(t *testing.T) {
metadata := NewMetadataV12()
err := Decode(MustHexDecodeString(s.hexData), metadata)
assert.EqualValues(t, metadata.Version, 12)
assert.NoError(t, err)
data, err := Encode(metadata)
assert.NoError(t, err)
assert.Equal(t, s.hexData, HexEncodeToString(data))
})

}
}

func TestMetadataV12_ExistsModuleMetadata(t *testing.T) {
assert.True(t, exampleMetadataV12.ExistsModuleMetadata("EmptyModule"))
assert.False(t, exampleMetadataV12.ExistsModuleMetadata("NotExistModule"))
Expand Down
19 changes: 0 additions & 19 deletions types/metadataV13_example.go

This file was deleted.

3 changes: 0 additions & 3 deletions types/metadataV13_example_string.go

This file was deleted.

11 changes: 0 additions & 11 deletions types/metadataV13_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"

. "github.com/centrifuge/go-substrate-rpc-client/v4/types"
. "github.com/centrifuge/go-substrate-rpc-client/v4/types/codec"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -157,13 +156,3 @@ func TestMetadataV13_TestFindCallIndexWithUnknownFunction(t *testing.T) {
_, err := exampleMetadataV13.FindCallIndex("Module2_13.unknownFunction")
assert.Error(t, err)
}

func TestNewMetadataV13_Decode(t *testing.T) {
metadata := NewMetadataV13()
err := Decode(MustHexDecodeString(ExamplaryMetadataV13SubstrateString), metadata)
assert.EqualValues(t, metadata.Version, 13)
assert.NoError(t, err)
data, err := Encode(metadata)
assert.NoError(t, err)
assert.Equal(t, ExamplaryMetadataV13SubstrateString, HexEncodeToString(data))
}
1 change: 1 addition & 0 deletions types/metadataV14_example.go

Large diffs are not rendered by default.

23 changes: 0 additions & 23 deletions types/metadataV4_example.go

This file was deleted.

10 changes: 0 additions & 10 deletions types/metadataV4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"

. "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"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -126,15 +125,6 @@ var exampleDoubleMapTypeV4 = DoubleMapTypeV4{

var exampleFunctionArgumentMetadata = FunctionArgumentMetadata{Name: "myFunctionName", Type: "myType"}

func TestMetadataV4_Decode(t *testing.T) {
metadata := NewMetadataV4()

err := Decode(MustHexDecodeString(ExamplaryMetadataV4String), metadata)
assert.NoError(t, err)

assert.Equal(t, *ExamplaryMetadataV4, *metadata)
}

func TestMetadataV4_EncodeDecode(t *testing.T) {
AssertRoundtrip(t, exampleMetadataV4)
}
Expand Down
20 changes: 0 additions & 20 deletions types/metadataV8_example.go

This file was deleted.

20 changes: 0 additions & 20 deletions types/metadataV9_example.go

This file was deleted.

Loading

0 comments on commit 9dfb473

Please sign in to comment.