Skip to content

Commit

Permalink
adding back matchers in the test
Browse files Browse the repository at this point in the history
  • Loading branch information
dadepo committed Feb 1, 2022
1 parent 470b2fc commit 543bef7
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/keymanager-server/test/unit/impl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ describe("keymanager", () => {
let slashingProtectionStub: Sinon.SinonStubbedInstance<SlashingProtection>;
let genesisValidatorRootStub: Sinon.SinonStubbedInstance<Uint8Array | Root>;
const interchange: Interchange = ("abc" as unknown) as Interchange;

const PASSWORD = "passfortesting";
// eslint-disable-next-line
const keyStoreStr = "{\"crypto\": {\"kdf\": {\"function\": \"scrypt\", \"params\": {\"dklen\": 32, \"n\": 262144, \"r\": 8, \"p\": 1, \"salt\": \"34d24f0a6f85b7b55d5ccc54efd0ba2955472a39a72d55e1c71fb770717639de\"}, \"message\": \"\"}, \"checksum\": {\"function\": \"sha256\", \"params\": {}, \"message\": \"c043032c9c50ebcaab5ec6edccad095d223ba5e7be40b2a39b8931ab931585a3\"}, \"cipher\": {\"function\": \"aes-128-ctr\", \"params\": {\"iv\": \"53e5deb6df661b998140ca59de04bd69\"}, \"message\": \"c3fa507c9fdb0bf14983a09175210b6d650d89451bb5a39f368e2f0421db0b14\"}}, \"description\": \"\", \"pubkey\": \"8cd1ea594e011cbdae67c583206aef8661f74a800082079e4edf96b86eb631fff236fcf6b87b57153c26d76c65bc7970\", \"path\": \"m/12381/3600/0/0/0\", \"uuid\": \"a7fa0c0f-edd6-4640-b46d-872db3696a36\", \"version\": 4}";


beforeEach(() => {
validatorStoreSub = sinon.createStubInstance(ValidatorStore);
slashingProtectionStub = sinon.createStubInstance(SlashingProtection);
Expand Down Expand Up @@ -66,7 +65,7 @@ describe("keymanager", () => {
genesisValidatorRootStub
);

void km.importKeystores([keyStoreStr], ["passfortesting"], "").then((result) => {
void km.importKeystores([keyStoreStr], [PASSWORD], "").then((result) => {
assert.equal(result.data.length, 1);
assert.equal(result.data[0].status, "duplicate");
done();
Expand All @@ -78,14 +77,15 @@ describe("keymanager", () => {
validatorStoreSub.hasVotingPubkey.withArgs(sinon.match.any).returns(false);
const fsStub = sinon
.stub(fs.promises, "writeFile")
.withArgs(sinon.match.any, keyStoreStr, {encoding: "utf8"})
.withArgs(sinon.match(/key_imported/), keyStoreStr, {encoding: "utf8"})
.resolves();

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
const lockFile = getLockFile();

sinon
const lockStub = sinon
.stub(lockFile, "lockSync")
.withArgs(sinon.match.any)
.withArgs(sinon.match(/json.lock/))
.callsFake(() => {
return;
});
Expand All @@ -97,9 +97,10 @@ describe("keymanager", () => {
["path"]
);

void km.importKeystores([keyStoreStr], ["passfortesting"], "").then((result) => {
void km.importKeystores([keyStoreStr], [PASSWORD], "").then((result) => {
assert.equal(validatorStoreSub.addSigner.called, true);
assert.equal(fsStub.called, true);
assert.equal(lockStub.called, true);
assert.equal(result.data.length, 1);
assert.equal(result.data[0].status, "imported");
done();
Expand All @@ -111,12 +112,13 @@ describe("keymanager", () => {
validatorStoreSub.hasVotingPubkey.withArgs(sinon.match.any).returns(false);
const fsStub = sinon
.stub(fs.promises, "writeFile")
.withArgs(sinon.match.any, keyStoreStr, {encoding: "utf8"})
.withArgs(sinon.match(/key_imported/), keyStoreStr, {encoding: "utf8"})
.resolves();

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
const lockFile = getLockFile();

sinon
const lockStub = sinon
.stub(lockFile, "lockSync")
.withArgs(sinon.match.any)
.callsFake(() => {
Expand All @@ -129,9 +131,10 @@ describe("keymanager", () => {
genesisValidatorRootStub
);

void km.importKeystores([keyStoreStr], ["passfortesting"], "").then((result) => {
void km.importKeystores([keyStoreStr], [PASSWORD], "").then((result) => {
assert.equal(validatorStoreSub.addSigner.called, true);
assert.equal(fsStub.called, false);
assert.equal(lockStub.called, false);
assert.equal(result.data.length, 1);
assert.equal(result.data[0].status, "imported");
done();
Expand Down

0 comments on commit 543bef7

Please sign in to comment.