1
1
import { expect } from 'chai'
2
2
3
3
import { ServiceRegistry } from '../build/typechain/contracts/ServiceRegistry'
4
+ import { Staking } from '../build/typechain/contracts/Staking'
4
5
5
- import * as deployment from './lib/deployment'
6
6
import { getAccounts , Account } from './lib/testHelpers'
7
+ import { NetworkFixture } from './lib/fixtures'
7
8
8
9
describe ( 'ServiceRegistry' , ( ) => {
9
- let me : Account
10
+ let governor : Account
10
11
let indexer : Account
12
+ let operator : Account
13
+
14
+ let fixture : NetworkFixture
11
15
12
16
let serviceRegistry : ServiceRegistry
13
- const geohash = '69y7hdrhm6mp'
17
+ let staking : Staking
14
18
15
19
const shouldRegister = async ( url : string , geohash : string ) => {
16
20
// Register the indexer service
@@ -26,23 +30,31 @@ describe('ServiceRegistry', () => {
26
30
}
27
31
28
32
before ( async function ( ) {
29
- ; [ me , indexer ] = await getAccounts ( )
33
+ ; [ governor , indexer , operator ] = await getAccounts ( )
34
+
35
+ fixture = new NetworkFixture ( )
36
+ ; ( { serviceRegistry, staking } = await fixture . load ( governor . signer , governor . signer ) )
30
37
} )
31
38
32
39
beforeEach ( async function ( ) {
33
- const controller = await deployment . deployController ( me . signer )
34
- serviceRegistry = await deployment . deployServiceRegistry ( me . signer )
40
+ await fixture . setUp ( )
41
+ } )
42
+
43
+ afterEach ( async function ( ) {
44
+ await fixture . tearDown ( )
35
45
} )
36
46
37
47
describe ( 'register' , function ( ) {
48
+ const url = 'https://192.168.2.1/'
49
+ const geo = '69y7hdrhm6mp'
50
+
38
51
it ( 'should allow registering' , async function ( ) {
39
- const url = 'https://192.168.2.1/'
40
- await shouldRegister ( url , geohash )
52
+ await shouldRegister ( url , geo )
41
53
} )
42
54
43
55
it ( 'should allow registering with a very long string' , async function ( ) {
44
56
const url = 'https://' + 'a' . repeat ( 125 ) + '.com'
45
- await shouldRegister ( url , geohash )
57
+ await shouldRegister ( url , geo )
46
58
} )
47
59
48
60
it ( 'should allow updating a registration' , async function ( ) {
@@ -56,14 +68,35 @@ describe('ServiceRegistry', () => {
56
68
const tx = serviceRegistry . connect ( indexer . signer ) . register ( '' , '' )
57
69
await expect ( tx ) . revertedWith ( 'Service must specify a URL' )
58
70
} )
71
+
72
+ describe ( 'operator' , function ( ) {
73
+ it ( 'reject register from unauthorized operator' , async function ( ) {
74
+ const tx = serviceRegistry
75
+ . connect ( operator . signer )
76
+ . registerFor ( indexer . address , 'http://thegraph.com' , '' )
77
+ await expect ( tx ) . revertedWith ( '!auth' )
78
+ } )
79
+
80
+ it ( 'should register from operator' , async function ( ) {
81
+ // Auth and register
82
+ await staking . connect ( indexer . signer ) . setOperator ( operator . address , true )
83
+ await serviceRegistry . connect ( operator . signer ) . registerFor ( indexer . address , url , geo )
84
+
85
+ // Updated state
86
+ const indexerService = await serviceRegistry . services ( indexer . address )
87
+ expect ( indexerService . url ) . eq ( url )
88
+ expect ( indexerService . geohash ) . eq ( geo )
89
+ } )
90
+ } )
59
91
} )
60
92
61
93
describe ( 'unregister' , function ( ) {
62
- it ( 'should unregister existing registration' , async function ( ) {
63
- const url = 'https://thegraph.com '
94
+ const url = 'https://192.168.2.1/'
95
+ const geo = '69y7hdrhm6mp '
64
96
97
+ it ( 'should unregister existing registration' , async function ( ) {
65
98
// Register the indexer service
66
- await serviceRegistry . connect ( indexer . signer ) . register ( url , geohash )
99
+ await serviceRegistry . connect ( indexer . signer ) . register ( url , geo )
67
100
68
101
// Unregister the indexer service
69
102
const tx = serviceRegistry . connect ( indexer . signer ) . unregister ( )
@@ -74,5 +107,30 @@ describe('ServiceRegistry', () => {
74
107
const tx = serviceRegistry . connect ( indexer . signer ) . unregister ( )
75
108
await expect ( tx ) . revertedWith ( 'Service already unregistered' )
76
109
} )
110
+
111
+ describe ( 'operator' , function ( ) {
112
+ it ( 'reject unregister from unauthorized operator' , async function ( ) {
113
+ // Register the indexer service
114
+ await serviceRegistry . connect ( indexer . signer ) . register ( url , geo )
115
+
116
+ // Unregister
117
+ const tx = serviceRegistry . connect ( operator . signer ) . unregisterFor ( indexer . address )
118
+ await expect ( tx ) . revertedWith ( '!auth' )
119
+ } )
120
+
121
+ it ( 'should unregister from operator' , async function ( ) {
122
+ // Register the indexer service
123
+ await serviceRegistry . connect ( indexer . signer ) . register ( url , geo )
124
+
125
+ // Auth and unregister
126
+ await staking . connect ( indexer . signer ) . setOperator ( operator . address , true )
127
+ await serviceRegistry . connect ( operator . signer ) . unregisterFor ( indexer . address )
128
+
129
+ // Updated state
130
+ const indexerService = await serviceRegistry . services ( indexer . address )
131
+ expect ( indexerService . url ) . eq ( '' )
132
+ expect ( indexerService . geohash ) . eq ( '' )
133
+ } )
134
+ } )
77
135
} )
78
136
} )
0 commit comments