Skip to content

Commit

Permalink
FIx cn tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jowlee committed Sep 21, 2022
1 parent 0b65fc9 commit bc64d0f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ const _issueUpdateReplicaSetOp = async (
}ms for userId=${userId} wallet=${wallet}`
)

const { blocknumber, blockHash } =
const { blocknumber } =
await audiusLibs.User.updateEntityManagerReplicaSet({
userId,
primary: newReplicaSetSPIds[0], // new primary
Expand Down Expand Up @@ -828,7 +828,7 @@ const _canReconfig = async ({
let error
try {
const encodedUserId = libs.Utils.encodeHashId(userId)
const spResponse = await libs.DiscoveryProvider.getUserReplicaSet({
const spResponse = await libs.discoveryProvider.getUserReplicaSet({
encodedUserId
})
const chainPrimarySpId = spResponse?.primarySpID
Expand Down
26 changes: 25 additions & 1 deletion creator-node/test/lib/libsMock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const sinon = require('sinon')
const { encode, decode } = require('../../src/hashids')

function getLibsMock() {
const libsMock = {
Expand Down Expand Up @@ -67,11 +68,34 @@ function getLibsMock() {
Playlist: {
getPlaylists: sinon.mock().atLeast(1)
},
Utils: {
encodeHashId: sinon.mock().atLeast(1)
},
discoveryProvider: {
discoveryProviderEndpoint: 'http://docker.for.mac.localhost:5000'
discoveryProviderEndpoint: 'http://docker.for.mac.localhost:5000',
getUserReplicaSet: sinon.mock().atLeast(1)
}
}

libsMock.Utils.encodeHashId.callsFake((id) => {
return encode(id)
})

libsMock.discoveryProvider.getUserReplicaSet.callsFake(({ encodedUserId }) => {
const user_id = decode(encodedUserId)
return {
user_id,
"wallet": '0xadd36bad12002f1097cdb7ee24085c28e960fc32',
"primary": 'http://mock-cn1.audius.co',
"secondary1": 'http://mock-cn2.audius.co',
"secondary2": 'http://mock-cn3.audius.co',
"primarySpID": 1,
"secondary1SpID": 2,
"secondary2SpID": 3
}
})


libsMock.contracts.UserReplicaSetManagerClient.getUserReplicaSet.returns({
primaryId: 1,
secondaryIds: [2, 3]
Expand Down
35 changes: 34 additions & 1 deletion creator-node/test/updateReplicaSet.jobProcessor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { getApp } = require('./lib/app')
const { getLibsMock } = require('./lib/libsMock')

const config = require('../src/config')
const { encode, decode } = require('../src/hashids')
const {
SyncType,
RECONFIG_MODES,
Expand Down Expand Up @@ -82,15 +83,47 @@ describe('test updateReplicaSet job processor', function () {
const autoSelectCreatorNodesStub = sandbox
.stub()
.resolves({ services: healthyNodes })
const _updateReplicaSet = sandbox
.stub()
.resolves({ blocknumber: 10 })

const audiusLibsStub = {
ServiceProvider: {
autoSelectCreatorNodes: autoSelectCreatorNodesStub
},
User: {
updateEntityManagerReplicaSet: _updateReplicaSet,
_waitForReplicaSetDiscoveryIndexing: sandbox.stub()
},
contracts: {
UserReplicaSetManagerClient: {
updateReplicaSet: updateReplicaSetStub,
_updateReplicaSet: updateReplicaSetStub
_updateReplicaSet
}
},
Utils: {
encodeHashId: sandbox
.mock()
.callsFake((id) => {
return encode(id)
})
},
discoveryProvider: {
getUserReplicaSet: sandbox
.mock()
.callsFake(({ encodedUserId }) => {
const user_id = decode(encodedUserId)
return {
user_id,
"wallet": '0x123456789',
"primary": 'http://mock-cn1.audius.co',
"secondary1": 'http://mock-cn2.audius.co',
"secondary2": 'http://mock-cn3.audius.co',
"primarySpID": 1,
"secondary1SpID": 2,
"secondary2SpID": 3
}
})
}
}
return proxyquire(
Expand Down

0 comments on commit bc64d0f

Please sign in to comment.