(t *testing.T)
| 42 | ) |
| 43 | |
| 44 | func TestNewBusService(t *testing.T) { |
| 45 | Convey("Create a BusService with mock bp", t, func() { |
| 46 | var ( |
| 47 | err error |
| 48 | cleanup func() |
| 49 | ) |
| 50 | cleanup, _, err = initNodeChainBusService() |
| 51 | So(err, ShouldBeNil) |
| 52 | |
| 53 | var ( |
| 54 | privKey *asymmetric.PrivateKey |
| 55 | pubKey *asymmetric.PublicKey |
| 56 | addr proto.AccountAddress |
| 57 | testCheckInterval = 30 * time.Second |
| 58 | count uint32 |
| 59 | ) |
| 60 | privKey, err = kms.GetLocalPrivateKey() |
| 61 | So(err, ShouldBeNil) |
| 62 | pubKey = privKey.PubKey() |
| 63 | addr, err = crypto.PubKeyHash(pubKey) |
| 64 | So(err, ShouldBeNil) |
| 65 | ctx, cancelFunc := context.WithCancel(context.Background()) |
| 66 | defer cancelFunc() |
| 67 | bs := NewBusService(ctx, addr, testCheckInterval) |
| 68 | topic := fmt.Sprintf("/%s/", testOddBlocks.Transactions[0].GetTransactionType().String()) |
| 69 | err = bs.Subscribe(topic, func(tx interfaces.Transaction, c uint32) { |
| 70 | atomic.AddUint32(&count, 1) |
| 71 | }) |
| 72 | So(err, ShouldBeNil) |
| 73 | bs.extractTxs(&testEventBlocks, 1) |
| 74 | So(count, ShouldEqual, len(testEventBlocks.Transactions)) |
| 75 | |
| 76 | bs.Start() |
| 77 | |
| 78 | time.Sleep(4 * time.Second) |
| 79 | |
| 80 | c := atomic.LoadUint32(&bs.blockCount) |
| 81 | if c%2 == 0 { |
| 82 | dbMap := bs.GetCurrentDBMapping() |
| 83 | for _, profile := range testEventProfiles { |
| 84 | // test RequestSQLProfile |
| 85 | p, ok := bs.RequestSQLProfile(profile.ID) |
| 86 | So(ok, ShouldBeTrue) |
| 87 | So(p, ShouldResemble, profile) |
| 88 | |
| 89 | // test GetCurrentDBMapping |
| 90 | p, ok = dbMap[profile.ID] |
| 91 | So(ok, ShouldBeTrue) |
| 92 | So(profile, ShouldResemble, p) |
| 93 | |
| 94 | // test RequestPermStat |
| 95 | permStat, ok := bs.RequestPermStat(profile.ID, testAddr) |
| 96 | So(ok, ShouldBeTrue) |
| 97 | So(permStat.Status, ShouldEqual, profile.Users[0].Status) |
| 98 | So(permStat.Permission, ShouldResemble, profile.Users[0].Permission) |
| 99 | permStat, ok = bs.RequestPermStat(profile.ID, testNotExistAddr) |
| 100 | } |
| 101 | p, ok := bs.RequestSQLProfile(testNotExistID) |
nothing calls this directly
no test coverage detected