Skip to content

Commit bc64d0f

Browse files
committed
FIx cn tests
1 parent 0b65fc9 commit bc64d0f

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

creator-node/src/services/stateMachineManager/stateReconciliation/updateReplicaSet.jobProcessor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ const _issueUpdateReplicaSetOp = async (
701701
}ms for userId=${userId} wallet=${wallet}`
702702
)
703703

704-
const { blocknumber, blockHash } =
704+
const { blocknumber } =
705705
await audiusLibs.User.updateEntityManagerReplicaSet({
706706
userId,
707707
primary: newReplicaSetSPIds[0], // new primary
@@ -828,7 +828,7 @@ const _canReconfig = async ({
828828
let error
829829
try {
830830
const encodedUserId = libs.Utils.encodeHashId(userId)
831-
const spResponse = await libs.DiscoveryProvider.getUserReplicaSet({
831+
const spResponse = await libs.discoveryProvider.getUserReplicaSet({
832832
encodedUserId
833833
})
834834
const chainPrimarySpId = spResponse?.primarySpID

creator-node/test/lib/libsMock.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const sinon = require('sinon')
2+
const { encode, decode } = require('../../src/hashids')
23

34
function getLibsMock() {
45
const libsMock = {
@@ -67,11 +68,34 @@ function getLibsMock() {
6768
Playlist: {
6869
getPlaylists: sinon.mock().atLeast(1)
6970
},
71+
Utils: {
72+
encodeHashId: sinon.mock().atLeast(1)
73+
},
7074
discoveryProvider: {
71-
discoveryProviderEndpoint: 'http://docker.for.mac.localhost:5000'
75+
discoveryProviderEndpoint: 'http://docker.for.mac.localhost:5000',
76+
getUserReplicaSet: sinon.mock().atLeast(1)
7277
}
7378
}
7479

80+
libsMock.Utils.encodeHashId.callsFake((id) => {
81+
return encode(id)
82+
})
83+
84+
libsMock.discoveryProvider.getUserReplicaSet.callsFake(({ encodedUserId }) => {
85+
const user_id = decode(encodedUserId)
86+
return {
87+
user_id,
88+
"wallet": '0xadd36bad12002f1097cdb7ee24085c28e960fc32',
89+
"primary": 'http://mock-cn1.audius.co',
90+
"secondary1": 'http://mock-cn2.audius.co',
91+
"secondary2": 'http://mock-cn3.audius.co',
92+
"primarySpID": 1,
93+
"secondary1SpID": 2,
94+
"secondary2SpID": 3
95+
}
96+
})
97+
98+
7599
libsMock.contracts.UserReplicaSetManagerClient.getUserReplicaSet.returns({
76100
primaryId: 1,
77101
secondaryIds: [2, 3]

creator-node/test/updateReplicaSet.jobProcessor.test.js

+34-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { getApp } = require('./lib/app')
88
const { getLibsMock } = require('./lib/libsMock')
99

1010
const config = require('../src/config')
11+
const { encode, decode } = require('../src/hashids')
1112
const {
1213
SyncType,
1314
RECONFIG_MODES,
@@ -82,15 +83,47 @@ describe('test updateReplicaSet job processor', function () {
8283
const autoSelectCreatorNodesStub = sandbox
8384
.stub()
8485
.resolves({ services: healthyNodes })
86+
const _updateReplicaSet = sandbox
87+
.stub()
88+
.resolves({ blocknumber: 10 })
89+
8590
const audiusLibsStub = {
8691
ServiceProvider: {
8792
autoSelectCreatorNodes: autoSelectCreatorNodesStub
8893
},
94+
User: {
95+
updateEntityManagerReplicaSet: _updateReplicaSet,
96+
_waitForReplicaSetDiscoveryIndexing: sandbox.stub()
97+
},
8998
contracts: {
9099
UserReplicaSetManagerClient: {
91100
updateReplicaSet: updateReplicaSetStub,
92-
_updateReplicaSet: updateReplicaSetStub
101+
_updateReplicaSet
93102
}
103+
},
104+
Utils: {
105+
encodeHashId: sandbox
106+
.mock()
107+
.callsFake((id) => {
108+
return encode(id)
109+
})
110+
},
111+
discoveryProvider: {
112+
getUserReplicaSet: sandbox
113+
.mock()
114+
.callsFake(({ encodedUserId }) => {
115+
const user_id = decode(encodedUserId)
116+
return {
117+
user_id,
118+
"wallet": '0x123456789',
119+
"primary": 'http://mock-cn1.audius.co',
120+
"secondary1": 'http://mock-cn2.audius.co',
121+
"secondary2": 'http://mock-cn3.audius.co',
122+
"primarySpID": 1,
123+
"secondary1SpID": 2,
124+
"secondary2SpID": 3
125+
}
126+
})
94127
}
95128
}
96129
return proxyquire(

0 commit comments

Comments
 (0)