diff --git a/package.json b/package.json index 486900f..12a8d90 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@bancor/carbon-sdk", "type": "module", "source": "src/index.ts", - "version": "0.0.80-DEV", + "version": "0.0.81-DEV", "description": "The SDK is a READ-ONLY tool, intended to facilitate working with Carbon contracts. It's a convenient wrapper around our matching algorithm, allowing programs and users get a ready to use transaction data that will allow them to manage strategies and fulfill trades", "main": "dist/index.js", "module": "dist/index.js", diff --git a/src/chain-cache/ChainCache.ts b/src/chain-cache/ChainCache.ts index 93651f6..5893b40 100644 --- a/src/chain-cache/ChainCache.ts +++ b/src/chain-cache/ChainCache.ts @@ -25,7 +25,7 @@ import { import { Logger } from '../common/logger'; const logger = new Logger('ChainCache.ts'); -const schemeVersion = 4; // bump this when the serialization format changes +const schemeVersion = 5; // bump this when the serialization format changes type PairToStrategiesMap = { [key: string]: EncodedStrategy[] }; type StrategyById = { [key: string]: EncodedStrategy }; @@ -458,7 +458,7 @@ export class ChainCache extends (EventEmitter as new () => TypedEventEmitter s.id !== strategy.id + (s) => !s.id.eq(strategy.id) ); strategies.push(strategy); this._strategiesByPair[key] = strategies; @@ -479,7 +479,7 @@ export class ChainCache extends (EventEmitter as new () => TypedEventEmitter s.id !== strategy.id + (s) => !s.id.eq(strategy.id) ); this._strategiesByPair[key] = strategies; this._removeStrategyOrders(strategy); diff --git a/tests/ChainCache.spec.ts b/tests/ChainCache.spec.ts index bdce94f..92dd51e 100644 --- a/tests/ChainCache.spec.ts +++ b/tests/ChainCache.spec.ts @@ -140,6 +140,17 @@ describe('ChainCache', () => { cache.applyBatchedUpdates(5, [], [], [], []); expect(affectedPairs).to.deep.equal([['abc', 'xyz']]); }); + it('should contain a single copy of a strategy that was updated', async () => { + const cache = new ChainCache(); + const encodedStrategy1_mod = { + ...encodedStrategy1, + id: BigNumber.from(encodedStrategy1.id.toString()), + }; + cache.addPair('abc', 'xyz', [encodedStrategy1]); + cache.applyBatchedUpdates(10, [], [], [encodedStrategy1_mod], []); + const strategies = await cache.getStrategiesByPair('abc', 'xyz'); + expect(strategies).to.have.length(1); + }); }); describe('cache miss', () => { it('getStrategiesByPair call miss handler when pair is not cached', async () => {