Skip to content

Commit

Permalink
Merge pull request #2417 from dedis/use_default_db
Browse files Browse the repository at this point in the history
Use LocalCache per default
  • Loading branch information
cgrigis committed Dec 3, 2020
2 parents 0303996 + a628b8e commit c9184a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion external/js/cothority/spec/byzcoin/byzcoin-rpc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Long from "long";
import { ByzCoinRPC } from "../../src/byzcoin";
import { ByzCoinRPC, CONFIG_INSTANCE_ID } from "../../src/byzcoin";
import { LocalCache } from "../../src/byzcoin/byzcoin-rpc";
import DarcInstance from "../../src/byzcoin/contracts/darc-instance";
import Instance from "../../src/byzcoin/instance";
Expand Down Expand Up @@ -48,6 +48,17 @@ describe("ByzCoinRPC Tests", () => {
expect(rpc2.getConfig().blockInterval.toNumber()).toEqual(rpc.getConfig().blockInterval.toNumber());
});

it("should use a LocalCache when no DB is given", async () => {
const darc = ByzCoinRPC.makeGenesisDarc([SIGNER], roster);
const rpc = await ByzCoinRPC.newByzCoinRPC(roster, darc, BLOCK_INTERVAL);

const rpc2 = await ByzCoinRPC.fromByzcoin(roster, rpc.getGenesis().hash);
await rpc2.updateConfig();

const config = await rpc2.instanceObservable(CONFIG_INSTANCE_ID);
expect(config.getValue().contractID).toBe("config");
});

it("should throw an error for non-existing instance or wrong type", async () => {
const darc = ByzCoinRPC.makeGenesisDarc([SIGNER], roster);
const rpc = await ByzCoinRPC.newByzCoinRPC(roster, darc, BLOCK_INTERVAL);
Expand Down
2 changes: 1 addition & 1 deletion external/js/cothority/src/byzcoin/byzcoin-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default class ByzCoinRPC implements ICounterUpdater {
const di = await DarcInstance.fromByzcoin(rpc, ccProof.stateChangeBody.darcID, waitMatch, interval);

rpc.genesisDarc = di.darc;
rpc.db = storage;
rpc.db = storage ? storage : new LocalCache();

return rpc;
}
Expand Down

0 comments on commit c9184a5

Please sign in to comment.