trac-msb 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +6 -5
- package/msb.mjs +8 -12
- package/package.json +1 -1
- package/rpc/handlers.mjs +26 -33
- package/rpc/rpc_services.js +126 -0
- package/src/core/network/Network.js +29 -16
- package/src/core/network/services/ConnectionManager.js +252 -60
- package/src/core/network/services/MessageOrchestrator.js +95 -0
- package/src/core/network/services/ValidatorObserverService.js +56 -20
- package/src/index.js +200 -388
- package/src/utils/cliCommands.js +280 -0
- package/src/utils/constants.js +5 -4
- package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +6 -9
- package/tests/acceptance/v1/tx/tx.test.mjs +7 -12
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +14 -22
- package/tests/helpers/autobaseTestHelpers.js +47 -0
- package/tests/helpers/transactionPayloads.mjs +78 -0
- package/tests/unit/network/ConnectionManager.test.js +38 -69
|
@@ -50,7 +50,6 @@ test('ConnectionManager', () => {
|
|
|
50
50
|
reset()
|
|
51
51
|
const connectionManager = makeManager()
|
|
52
52
|
t.is(connectionManager.connectionCount(), connections.length, 'should have the same length')
|
|
53
|
-
|
|
54
53
|
const data = createConnection(testKeyPair5.publicKey)
|
|
55
54
|
connectionManager.addValidator(data.key, data.connection)
|
|
56
55
|
t.is(connectionManager.connectionCount(), connections.length + 1, 'should have the same length')
|
|
@@ -70,6 +69,31 @@ test('ConnectionManager', () => {
|
|
|
70
69
|
connectionManager.addValidator(toNotAdd.key, toNotAdd.connection)
|
|
71
70
|
t.is(connectionManager.connectionCount(), maxConnections, 'should not increase length')
|
|
72
71
|
})
|
|
72
|
+
|
|
73
|
+
test('does not add new validator when pool is full', async t => {
|
|
74
|
+
reset()
|
|
75
|
+
const maxConnections = 2
|
|
76
|
+
const localConnections = [
|
|
77
|
+
createConnection(testKeyPair1.publicKey),
|
|
78
|
+
createConnection(testKeyPair2.publicKey),
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
const connectionManager = new ConnectionManager({ maxValidators: maxConnections })
|
|
82
|
+
localConnections.forEach(({ key, connection }) => {
|
|
83
|
+
connectionManager.addValidator(key, connection)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
t.is(connectionManager.connectionCount(), maxConnections, 'pool should be full')
|
|
87
|
+
|
|
88
|
+
const newConn = createConnection(testKeyPair3.publicKey)
|
|
89
|
+
connectionManager.addValidator(newConn.key, newConn.connection)
|
|
90
|
+
|
|
91
|
+
t.is(connectionManager.connectionCount(), maxConnections, 'should stay at max size')
|
|
92
|
+
t.not(connectionManager.connected(newConn.key), 'new validator should not be in the pool')
|
|
93
|
+
|
|
94
|
+
const remainingOld = localConnections.filter(c => connectionManager.connected(c.key)).length
|
|
95
|
+
t.is(remainingOld, 2, 'all of the old validators should remain')
|
|
96
|
+
})
|
|
73
97
|
})
|
|
74
98
|
|
|
75
99
|
test('connected', async t => {
|
|
@@ -93,84 +117,29 @@ test('ConnectionManager', () => {
|
|
|
93
117
|
reset()
|
|
94
118
|
const connectionManager = makeManager()
|
|
95
119
|
|
|
96
|
-
connectionManager.send([1,2,3,4])
|
|
97
|
-
t.ok(connections[0].connection.messenger.send.calledWith([1,2,3,4]), 'first on the list should have been called')
|
|
98
|
-
})
|
|
120
|
+
const target = connectionManager.send([1,2,3,4])
|
|
99
121
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
for (let i = 0; i < 10; i++) {
|
|
105
|
-
connectionManager.send([1,2,3,4])
|
|
106
|
-
t.ok(connections[0].connection.messenger.send.calledWith([1,2,3,4]), 'first on the list should have been called')
|
|
107
|
-
}
|
|
122
|
+
const totalCalls = connections.reduce((sum, con) => sum + con.connection.messenger.send.callCount, 0)
|
|
123
|
+
t.is(totalCalls, 1, 'should send to exactly one validator')
|
|
124
|
+
t.ok(target, 'should return a target public key')
|
|
108
125
|
})
|
|
109
126
|
|
|
110
|
-
test('
|
|
127
|
+
test('does not throw on individual send errors', async t => {
|
|
111
128
|
reset()
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
for (let i = 0; i < 10; i++) {
|
|
115
|
-
connectionManager.send([1,2,3,4])
|
|
116
|
-
t.ok(connections[0].connection.messenger.send.calledWith([1,2,3,4]), 'first on the list should have been called')
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
for (let i = 0; i < 10; i++) {
|
|
120
|
-
connectionManager.send([1,2,3,4])
|
|
121
|
-
t.ok(connections[1].connection.messenger.send.calledWith([1,2,3,4]), 'first on the list should have been called')
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
for (let i = 0; i < 10; i++) {
|
|
125
|
-
connectionManager.send([1,2,3,4])
|
|
126
|
-
t.ok(connections[2].connection.messenger.send.calledWith([1,2,3,4]), 'first on the list should have been called')
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
for (let i = 0; i < 10; i++) {
|
|
130
|
-
connectionManager.send([1,2,3,4])
|
|
131
|
-
t.ok(connections[3].connection.messenger.send.calledWith([1,2,3,4]), 'first on the list should have been called')
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
t.is(connections[0].connection.messenger.send.callCount, 10, 'first should have been called 10 times')
|
|
135
|
-
t.is(connections[1].connection.messenger.send.callCount, 10, 'second should have been called 10 times')
|
|
136
|
-
t.is(connections[2].connection.messenger.send.callCount, 10, 'third should have been called 10 times')
|
|
137
|
-
t.is(connections[3].connection.messenger.send.callCount, 10, 'fourth should have been called 10 times')
|
|
138
|
-
|
|
139
|
-
connectionManager.send([1,2,3,4])
|
|
140
|
-
t.ok(connections[0].connection.messenger.send.calledWith([1,2,3,4]), 'first on the list should have been called')
|
|
141
|
-
t.is(connections[0].connection.messenger.send.callCount, 11, 'first should have been called 11 times')
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
test('rotates on exception', async t => {
|
|
145
|
-
reset()
|
|
146
|
-
const conns = [
|
|
129
|
+
const errorConnections = [
|
|
147
130
|
createConnection(testKeyPair7.publicKey),
|
|
148
131
|
createConnection(testKeyPair8.publicKey),
|
|
149
|
-
createConnection(testKeyPair9.publicKey),
|
|
150
132
|
]
|
|
151
133
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const connectionManager = makeManager(5, conns)
|
|
156
|
-
connectionManager.send([1,2,3,4])
|
|
157
|
-
|
|
158
|
-
t.is(conns[0].connection.messenger.send.callCount, 1, 'first should have been called 10 times')
|
|
159
|
-
t.is(conns[1].connection.messenger.send.callCount, 1, 'second should have been called 10 times')
|
|
160
|
-
t.is(conns[2].connection.messenger.send.callCount, 1, 'third should have been called 10 times')
|
|
161
|
-
})
|
|
162
|
-
})
|
|
134
|
+
errorConnections.forEach(con => {
|
|
135
|
+
con.connection.messenger.send = sinon.stub().throws(new Error())
|
|
136
|
+
})
|
|
163
137
|
|
|
164
|
-
|
|
165
|
-
test('resets the rotation', async t => {
|
|
166
|
-
reset()
|
|
167
|
-
const connectionManager = makeManager()
|
|
138
|
+
const connectionManager = makeManager(5, errorConnections)
|
|
168
139
|
|
|
169
|
-
|
|
170
|
-
t.ok(connections[0].connection.messenger.send.calledWith([1,2,3,4]), 'first on the list should have been called')
|
|
171
|
-
connectionManager.rotate() // rotate
|
|
140
|
+
t.is(errorConnections.length, 2, 'should have two connections')
|
|
172
141
|
connectionManager.send([1,2,3,4])
|
|
173
|
-
t.ok(
|
|
142
|
+
t.ok(true, 'send should not throw even if individual sends fail')
|
|
174
143
|
})
|
|
175
144
|
})
|
|
176
145
|
|
|
@@ -216,4 +185,4 @@ test('ConnectionManager', () => {
|
|
|
216
185
|
t.is(connectionCount, connectionManager.connectionCount() + 1, 'first on the list should have been called')
|
|
217
186
|
})
|
|
218
187
|
})
|
|
219
|
-
})
|
|
188
|
+
})
|