Skip to content

Commit

Permalink
chore: run nwaku as github action
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Apr 26, 2024
1 parent 78b1da7 commit 63c5abc
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 48 deletions.
1 change: 0 additions & 1 deletion .github/.env

This file was deleted.

6 changes: 6 additions & 0 deletions .github/docker-compose/nwaku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
nwaku:
image: "quay.io/wakuorg/nwaku-pr:2636-rln-v2"
command: ["--relay --store --nodekey=1122334455667788990011223344556677889900112233445566778899001122"]
ports:
- "60000"
47 changes: 23 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: xom9ikk/dotenv@v2
with:
path: ".github/"
- run: |
echo "go_version=${{ env.GO_VERSION }}" >> $GITHUB_OUTPUT
- run: |
VERSION=$(cat ./VERSION)
echo "waku_version=$VERSION" >> $GITHUB_OUTPUT
Expand All @@ -73,9 +66,9 @@ jobs:
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ needs.env.outputs.go_version }}
go-version-file: 'go.mod'
cache: false

- name: Execute golangci-lint
Expand Down Expand Up @@ -112,19 +105,19 @@ jobs:
key: ${{ runner.os }}-vendor-modules-${{ steps.submodules.outputs.hash }}

- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ needs.env.outputs.go_version }}
go-version-file: 'go.mod'
cache: false

- name: Build binary
run: make
# - name: Build binary
# run: make

- name: Build library
run: make static-library dynamic-library
# - name: Build library
# run: make static-library dynamic-library

- name: Build examples
run: make build-example
# - name: Build examples
# run: make build-example

test:
needs: [changes, env]
Expand Down Expand Up @@ -154,15 +147,21 @@ jobs:
key: ${{ runner.os }}-vendor-modules-${{ steps.submodules.outputs.hash }}

- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ needs.env.outputs.go_version }}
go-version-file: 'go.mod'
cache: false

- name: "Run tests"
run: make ${{ matrix.tests }}
# - name: "Run tests"
# run: make ${{ matrix.tests }}

# - name: "Run onchain-tests"
# run: |
# docker compose -f .github/docker-compose/ganache.yml up -d
# make test-onchain${{ matrix.tests == 'test-with-race' && '-with-race' || '' }}

- name: "Run onchain-tests"
- name: "Run storev3 tests"
run: |
docker compose -f .github/docker-compose/ganache.yml up -d
make test-onchain${{ matrix.tests == 'test-with-race' && '-with-race' || '' }}
docker compose -f .github/docker-compose/nwaku.yml up -d
nwaku_port=$(docker-compose -f .github/docker-compose/nwaku.yml port nwaku 60000)
echo "Mapped port for nwaku: $nwaku_port"
2 changes: 1 addition & 1 deletion examples/basic-relay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func write(ctx context.Context, wakuNode *node.WakuNode, contentTopic string, ms
if err != nil {
log.Error("Error sending a message", zap.Error(err))
}
log.Info("Published msg,", zap.String("data", string(msg.Payload)), logging.HexBytes("hash", hash))
log.Info("Published msg,", zap.String("data", string(msg.Payload)), logging.HexBytes("hash", hash.Bytes()))
}

func writeLoop(ctx context.Context, wakuNode *node.WakuNode, contentTopic string) {
Expand Down
16 changes: 8 additions & 8 deletions examples/chat2/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"github.com/waku-org/go-waku/waku/v2/payload"
"github.com/waku-org/go-waku/waku/v2/protocol"
"github.com/waku-org/go-waku/waku/v2/protocol/filter"
"github.com/waku-org/go-waku/waku/v2/protocol/legacy_store"
"github.com/waku-org/go-waku/waku/v2/protocol/lightpush"
wpb "github.com/waku-org/go-waku/waku/v2/protocol/pb"
"github.com/waku-org/go-waku/waku/v2/protocol/relay"
wrln "github.com/waku-org/go-waku/waku/v2/protocol/rln"
"github.com/waku-org/go-waku/waku/v2/protocol/store"
"github.com/waku-org/go-waku/waku/v2/utils"
"google.golang.org/protobuf/proto"
)
Expand Down Expand Up @@ -368,10 +368,10 @@ func (c *Chat) retrieveHistory(connectionWg *sync.WaitGroup) {
return
}

var storeOpt store.HistoryRequestOption
var storeOpt legacy_store.HistoryRequestOption
if c.options.Store.Node == nil {
c.ui.InfoMessage("No store node configured. Choosing one at random...")
storeOpt = store.WithAutomaticPeerSelection()
storeOpt = legacy_store.WithAutomaticPeerSelection()
} else {
peerID, err := (*c.options.Store.Node).ValueForProtocol(multiaddr.P_P2P)
if err != nil {
Expand All @@ -383,22 +383,22 @@ func (c *Chat) retrieveHistory(connectionWg *sync.WaitGroup) {
c.ui.ErrorMessage(err)
return
}
storeOpt = store.WithPeer(pID)
storeOpt = legacy_store.WithPeer(pID)
c.ui.InfoMessage(fmt.Sprintf("Querying historic messages from %s", peerID))

}

tCtx, cancel := context.WithTimeout(c.ctx, 10*time.Second)
defer cancel()

q := store.Query{
q := legacy_store.Query{
ContentTopics: []string{options.ContentTopic},
}

response, err := c.node.Store().Query(tCtx, q,
store.WithAutomaticRequestID(),
response, err := c.node.LegacyStore().Query(tCtx, q,
legacy_store.WithAutomaticRequestID(),
storeOpt,
store.WithPaging(false, 100))
legacy_store.WithPaging(false, 100))

if err != nil {
c.ui.ErrorMessage(fmt.Errorf("could not query storenode: %w", err))
Expand Down
4 changes: 2 additions & 2 deletions examples/chat2/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/waku-org/go-waku/waku/v2/node"
"github.com/waku-org/go-waku/waku/v2/peerstore"
"github.com/waku-org/go-waku/waku/v2/protocol/filter"
"github.com/waku-org/go-waku/waku/v2/protocol/legacy_store"
"github.com/waku-org/go-waku/waku/v2/protocol/lightpush"
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
"github.com/waku-org/go-waku/waku/v2/protocol/store"
)

func execute(options Options) {
Expand Down Expand Up @@ -77,7 +77,7 @@ func execute(options Options) {
return
}

err = addPeer(wakuNode, options.Store.Node, options.Relay.Topics.Value(), store.StoreID_v20beta4)
err = addPeer(wakuNode, options.Store.Node, options.Relay.Topics.Value(), legacy_store.StoreID_v20beta4)
if err != nil {
fmt.Println(err.Error())
return
Expand Down
4 changes: 3 additions & 1 deletion waku/persistence/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,10 @@ func (d *DBStore) Put(env *protocol.Envelope) error {
storedAt = env.Index().ReceiverTime
}

hash := env.Hash()

start := time.Now()
_, err = stmt.Exec(env.Index().Digest, env.Hash(), storedAt, env.Message().GetTimestamp(), env.Message().ContentTopic, env.PubsubTopic(), env.Message().Payload, env.Message().GetVersion())
_, err = stmt.Exec(env.Index().Digest, hash[:], storedAt, env.Message().GetTimestamp(), env.Message().ContentTopic, env.PubsubTopic(), env.Message().Payload, env.Message().GetVersion())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion waku/v2/protocol/envelope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestEnvelope(t *testing.T) {

require.Equal(
t,
[]byte{0x91, 0x0, 0xe4, 0xa5, 0xcf, 0xf7, 0x19, 0x27, 0x49, 0x81, 0x66, 0xb3, 0xdf, 0xc7, 0xa6, 0x31, 0xf0, 0x87, 0xc7, 0x29, 0xb4, 0x28, 0x83, 0xb9, 0x5c, 0x31, 0x25, 0x33, 0x3, 0xc9, 0x7, 0x95},
pb.ToMessageHash([]byte{0x91, 0x0, 0xe4, 0xa5, 0xcf, 0xf7, 0x19, 0x27, 0x49, 0x81, 0x66, 0xb3, 0xdf, 0xc7, 0xa6, 0x31, 0xf0, 0x87, 0xc7, 0x29, 0xb4, 0x28, 0x83, 0xb9, 0x5c, 0x31, 0x25, 0x33, 0x3, 0xc9, 0x7, 0x95}),
hash,
)
}
12 changes: 6 additions & 6 deletions waku/v2/protocol/pb/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestEnvelopeHash(t *testing.T) {

expected := []byte{0xb6, 0x59, 0x60, 0x7f, 0x2a, 0xae, 0x18, 0x84, 0x8d, 0xca, 0xa7, 0xd5, 0x1c, 0xb3, 0x7e, 0x6c, 0xc6, 0xfc, 0x33, 0x40, 0x2c, 0x70, 0x4f, 0xf0, 0xc0, 0x16, 0x33, 0x7d, 0x83, 0xad, 0x61, 0x50}
result := msg.Hash("test")
require.Equal(t, expected, result)
require.Equal(t, ToMessageHash(expected), result)
}

func TestEmptyMeta(t *testing.T) {
Expand All @@ -38,7 +38,7 @@ func TestEmptyMeta(t *testing.T) {

messageHash := msg.Hash(pubsubTopic)

require.Equal(t, "f0183c2e370e473ff471bbe1028d0d8a940949c02f3007a1ccd21fed356852a0", messageHash.String())
require.Equal(t, "0xf0183c2e370e473ff471bbe1028d0d8a940949c02f3007a1ccd21fed356852a0", messageHash.String())
}

func Test13ByteMeta(t *testing.T) {
Expand All @@ -52,7 +52,7 @@ func Test13ByteMeta(t *testing.T) {

messageHash := msg.Hash(pubsubTopic)

require.Equal(t, "f673cd2c9c973d685b52ca74c2559e001733a3a31a49ffc7b6e8713decba5a55", messageHash.String())
require.Equal(t, "0xf673cd2c9c973d685b52ca74c2559e001733a3a31a49ffc7b6e8713decba5a55", messageHash.String())
}

func TestZeroLenPayload(t *testing.T) {
Expand All @@ -66,7 +66,7 @@ func TestZeroLenPayload(t *testing.T) {

messageHash := msg.Hash(pubsubTopic)

require.Equal(t, "978ccc9a665029f9829d42d84e3a49ad3a4791cce53fb5a8b581ef43ad6b4d2f", messageHash.String())
require.Equal(t, "0x978ccc9a665029f9829d42d84e3a49ad3a4791cce53fb5a8b581ef43ad6b4d2f", messageHash.String())
}

func TestHashWithTimestamp(t *testing.T) {
Expand All @@ -78,11 +78,11 @@ func TestHashWithTimestamp(t *testing.T) {
msg.Version = proto.Uint32(1)

messageHash := msg.Hash(pubsubTopic)
require.Equal(t, "58e2fc032a82c4adeb967a8b87086d0d6fb304912f120d4404e6236add8f1f56", messageHash.String())
require.Equal(t, "0x58e2fc032a82c4adeb967a8b87086d0d6fb304912f120d4404e6236add8f1f56", messageHash.String())

msg.Timestamp = proto.Int64(123456789123456789)
messageHash = msg.Hash(pubsubTopic)
require.Equal(t, "978ccc9a665029f9829d42d84e3a49ad3a4791cce53fb5a8b581ef43ad6b4d2f", messageHash.String())
require.Equal(t, "0x978ccc9a665029f9829d42d84e3a49ad3a4791cce53fb5a8b581ef43ad6b4d2f", messageHash.String())
}

func TestIntToBytes(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions waku/v2/protocol/store/client_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package store
//go:build include_storev3_tests
// +build include_storev3_tests

//111go:build include_storev3_tests
// 111+build include_storev3_tests
package store

import (
"context"
Expand Down Expand Up @@ -43,7 +43,7 @@ func TestStoreClient(t *testing.T) {
err = wakuRelay.Start(context.Background())
require.NoError(t, err)

pm := peermanager.NewPeerManager(5, 5, utils.Logger())
pm := peermanager.NewPeerManager(5, 5, nil, utils.Logger())
pm.SetHost(host)
err = pm.SubscribeToRelayEvtBus(wakuRelay.Events())
require.NoError(t, err)
Expand Down

0 comments on commit 63c5abc

Please sign in to comment.