-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.go
59 lines (49 loc) · 1.4 KB
/
events.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: LGPL-3.0-only
package subtest
import (
"testing"
"time"
utils "github.com/Polarfox-DEX/polarfox-bridge/shared/substrate"
"github.com/ChainSafe/log15"
"github.com/centrifuge/go-substrate-rpc-client/types"
)
var TestTimeout = time.Second * 15
func WaitForRemarkEvent(t *testing.T, client *utils.Client, hash types.Hash) {
key, err := types.CreateStorageKey(client.Meta, "System", "Events", nil, nil)
if err != nil {
t.Fatal(err)
}
sub, err := client.Api.RPC.State.SubscribeStorageRaw([]types.StorageKey{key})
if err != nil {
t.Fatal(err)
}
timeout := time.After(TestTimeout)
for {
select {
case <-timeout:
t.Fatalf("Timed out waiting for proposal success/fail event")
case set := <-sub.Chan():
for _, chng := range set.Changes {
if !types.Eq(chng.StorageKey, key) || !chng.HasStorageData {
// skip, we are only interested in events with content
continue
}
// Decode the event records
events := utils.Events{}
err = types.EventRecordsRaw(chng.StorageData).DecodeEventRecords(client.Meta, &events)
if err != nil {
t.Fatal(err)
}
for _, evt := range events.Example_Remark {
if evt.Hash == hash {
log15.Info("Found matching Remark event", "hash", evt.Hash)
return
} else {
log15.Info("Found mismatched Remark event", "hash", evt.Hash)
}
}
}
}
}
}