Skip to content

Commit

Permalink
Merge pull request #20 from perun-network/update_rpc
Browse files Browse the repository at this point in the history
Update for new Perun-Polkadot-Node (Polkadot v1.9)
  • Loading branch information
NhoxxKienn authored Apr 25, 2024
2 parents 9ec28fc + 278643f commit 589d0ae
Show file tree
Hide file tree
Showing 35 changed files with 177 additions and 543 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.21
- name: Checkout
uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.45
version: v1.56.2

test:
name: Test
Expand All @@ -25,7 +25,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.21

- name: Checkout
uses: actions/checkout@v2
Expand All @@ -40,7 +40,7 @@ jobs:
${{ runner.os }}-go-
- name: Start Substrate node
run: docker run --rm -d --name substrate -p 9944:9944 ghcr.io/perun-network/polkadot-test-node:0.2.0
run: docker run --rm -d --name substrate -p 9944:9944 ghcr.io/perun-network/polkadot-test-node:0.4.0

- name: Wait for Substrate node
# Wait for port 9944 to listen.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cd perun-polkadot-backend
2. Start a local Substrate node with the Perun Pallet installed. See the [polkadot node] repository for more details.

```sh
docker run --rm -p 9944:9944 ghcr.io/perun-network/polkadot-test-node
docker run --rm -p 9944:9944 ghcr.io/perun-network/polkadot-test-node:0.4.0
```

3. Run the tests. This step needs a working [Go distribution](https://golang.org), see [go.mod](go.mod) for the required version.
Expand Down
2 changes: 1 addition & 1 deletion channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package channel
import (
"math/big"

"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/pkg/errors"
pchannel "perun.network/go-perun/channel"
Expand Down
7 changes: 4 additions & 3 deletions channel/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (
"math/big"
"time"

"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types/codec"
"github.com/perun-network/perun-polkadot-backend/pkg/substrate"
"github.com/pkg/errors"
pchannel "perun.network/go-perun/channel"
Expand All @@ -28,12 +29,12 @@ import (

// ScaleEncode encodes any struct according to the SCALE codec.
func ScaleEncode(obj interface{}) ([]byte, error) {
return types.EncodeToBytes(obj)
return codec.Encode(obj)
}

// ScaleDecode decodes any struct according to the SCALE codec.
func ScaleDecode(obj interface{}, data []byte) error {
return types.DecodeFromBytes(data, obj)
return codec.Decode(data, obj)
}

// MakeBalance creates a new Balance.
Expand Down
2 changes: 1 addition & 1 deletion channel/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package channel

import (
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion channel/pallet/adjudicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package pallet
import (
"context"

"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/pkg/errors"
pchannel "perun.network/go-perun/channel"
"perun.network/go-perun/log"
Expand Down
2 changes: 1 addition & 1 deletion channel/pallet/adjudicator_sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"fmt"
"time"

"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/perun-network/perun-polkadot-backend/channel"
pkg_sr25519 "github.com/perun-network/perun-polkadot-backend/pkg/sr25519"
"github.com/perun-network/perun-polkadot-backend/pkg/substrate"
Expand Down
2 changes: 1 addition & 1 deletion channel/pallet/adjudicator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestAdjudicator_Walkthrough(t *testing.T) {
dSetup := chtest.NewDepositSetup(params, state)
adjAlice := pallet.NewAdjudicator(s.Alice.Acc, s.Pallet, s.API, test.PastBlocks)
adjBob := pallet.NewAdjudicator(s.Bob.Acc, s.Pallet, s.API, test.PastBlocks)
ctx, cancel := context.WithTimeout(context.Background(), 100*s.BlockTime)
ctx, cancel := context.WithTimeout(context.Background(), 1000*s.BlockTime)
defer cancel()

// Fund
Expand Down
7 changes: 6 additions & 1 deletion channel/pallet/event_sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
package pallet

import (
"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"io"

"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"perun.network/go-perun/log"
pkgsync "polycry.pt/poly-go/sync"

Expand Down Expand Up @@ -60,6 +62,9 @@ func NewEventSub(source *substrate.EventSource, meta *types.Metadata, p EventPre
select {
case set := <-source.Events():
if err = sub.decodeEventRecords(set, meta); err != nil {
if err == io.EOF {
continue
}
sub.Log().Errorf("decoding event records: %v", err)
break loop
}
Expand Down
2 changes: 1 addition & 1 deletion channel/pallet/funder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"time"

"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/perun-network/perun-polkadot-backend/channel"
pchannel "perun.network/go-perun/channel"
"perun.network/go-perun/log"
Expand Down
2 changes: 1 addition & 1 deletion channel/pallet/pallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package pallet
import (
"errors"

"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
pchannel "perun.network/go-perun/channel"
"perun.network/go-perun/log"
pwallet "perun.network/go-perun/wallet"
Expand Down
4 changes: 2 additions & 2 deletions channel/pallet/test/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"math/big"
"testing"

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

Expand Down Expand Up @@ -131,7 +131,7 @@ func (s *Setup) AssertBalanceChanges(deltas map[types.AccountID]*big.Int, epsilo
for addr, delta := range deltas {
gotDelta := new(big.Int).Sub(before[addr], after[addr])
gotEpsilon := new(big.Int).Sub(delta, gotDelta)
msg := fmt.Sprintf("Addr: 0x%x, gotDelta: %v, wantDelta: %v, gotEps: %v, wantEps: %v", addr, substrate.NewDotFromPlank(gotDelta), substrate.NewDotFromPlank(delta), substrate.NewDotFromPlank(gotEpsilon), substrate.NewDotFromPlank(epsilon))
msg := fmt.Sprintf("Addr: 0x%x, gotDelta: %v, wantDelta: %v, gotEps: %v, wantEps: %v", addr, substrate.NewDotFromPlanck(gotDelta), substrate.NewDotFromPlanck(delta), substrate.NewDotFromPlanck(gotEpsilon), substrate.NewDotFromPlanck(epsilon))
require.True(s.T, gotEpsilon.CmpAbs(epsilon) <= 0, msg)
}
}
16 changes: 14 additions & 2 deletions client/appchannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ import (
"perun.network/go-perun/channel"
"perun.network/go-perun/client"
clienttest "perun.network/go-perun/client/test"
test "perun.network/go-perun/wallet/test"
"perun.network/go-perun/wire"
pkgtest "polycry.pt/poly-go/test"

"github.com/ChainSafe/go-schnorrkel"
pchannel "github.com/perun-network/perun-polkadot-backend/channel"
ptest "github.com/perun-network/perun-polkadot-backend/channel/pallet/test"
dotwallet "github.com/perun-network/perun-polkadot-backend/wallet/sr25519"
"github.com/stretchr/testify/require"
)

func TestAppChannel(t *testing.T) {
Expand All @@ -42,7 +44,17 @@ func TestAppChannel(t *testing.T) {
clienttest.NewPaula(t, setups[B]),
}

appAddress := test.NewRandomAddress(rng)
byteArray := [32]byte{
176, 115, 108, 113, 171, 155, 245, 248,
27, 234, 80, 36, 30, 145, 56, 217,
213, 25, 176, 99, 145, 198, 217, 248,
220, 159, 39, 241, 120, 209, 175, 8,
}
pk, err := schnorrkel.NewPublicKey(byteArray)
require.NoError(t, err)

appAddress := dotwallet.NewAddressFromPK(pk)
require.NoError(t, err)
app := channel.NewMockApp(appAddress)
channel.RegisterApp(app)

Expand Down
2 changes: 1 addition & 1 deletion client/dispute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"math/big"
"testing"

"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
pclient "perun.network/go-perun/client"
clienttest "perun.network/go-perun/client/test"
"perun.network/go-perun/wire"
Expand Down
2 changes: 1 addition & 1 deletion client/happy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"perun.network/go-perun/wire"
pkgtest "polycry.pt/poly-go/test"

"github.com/centrifuge/go-substrate-rpc-client/v3/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/perun-network/perun-polkadot-backend/channel"
"github.com/perun-network/perun-polkadot-backend/channel/pallet/test"
"github.com/perun-network/perun-polkadot-backend/wallet"
Expand Down
31 changes: 17 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
module github.com/perun-network/perun-polkadot-backend

go 1.17
go 1.21

require (
github.com/ChainSafe/go-schnorrkel v0.0.0-20210318173838-ccb5cd955283
github.com/centrifuge/go-substrate-rpc-client/v3 v3.0.2
github.com/ethereum/go-ethereum v1.10.12
github.com/ChainSafe/go-schnorrkel v1.1.0
github.com/centrifuge/go-substrate-rpc-client/v4 v4.2.1
github.com/ethereum/go-ethereum v1.10.20
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.7.2
github.com/vedhavyas/go-subkey v1.0.2
perun.network/go-perun v0.10.6
polycry.pt/poly-go v0.0.0-20220301085937-fb9d71b45a37
)

require (
github.com/btcsuite/btcd v0.21.0-beta // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v1.7.1 // indirect
github.com/decred/base58 v1.0.3 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/decred/base58 v1.0.4 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b // indirect
github.com/pierrec/xxHash v0.1.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/cors v1.8.0 // indirect
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
github.com/rs/cors v1.8.2 // indirect
github.com/vedhavyas/go-subkey/v2 v2.0.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 // indirect
golang.org/x/sys v0.6.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 589d0ae

Please sign in to comment.