diff --git a/validators/store/contract/contract_test.go b/validators/store/contract/contract_test.go index 75f7f8ffb4..b7d81bb35f 100644 --- a/validators/store/contract/contract_test.go +++ b/validators/store/contract/contract_test.go @@ -473,21 +473,26 @@ func TestContractValidatorStore_CacheChange(t *testing.T) { ) ) - testCache := func(t *testing.T, expectedCache map[uint64]validators.Validators) { + type testCase struct { + height uint64 + expected validators.Validators + } + + testCache := func(t *testing.T, testCases ...testCase) { t.Helper() - assert.Equal(t, len(expectedCache), store.validatorSetCache.Len()) + assert.Equal(t, len(testCases), store.validatorSetCache.Len()) - for height, expected := range expectedCache { - cache, ok := store.validatorSetCache.Get(height) + for _, testCase := range testCases { + cache, ok := store.validatorSetCache.Get(testCase.height) - assert.Truef(t, ok, "validators for %d must exist, but not found") - assert.Equal(t, expected, cache) + assert.Truef(t, ok, "validators at %d must exist, but not found", testCase.height) + assert.Equal(t, testCase.expected, cache) } } // initial cache is empty - testCache(t, nil) + testCache(t) // overflow doesn't occur assert.False( @@ -495,19 +500,21 @@ func TestContractValidatorStore_CacheChange(t *testing.T) { store.saveToValidatorSetCache(0, ecdsaValidators1), ) - testCache(t, map[uint64]validators.Validators{ - 0: ecdsaValidators1, - }) + testCache( + t, + testCase{height: 0, expected: ecdsaValidators1}, + ) assert.False( t, store.saveToValidatorSetCache(1, ecdsaValidators2), ) - testCache(t, map[uint64]validators.Validators{ - 0: ecdsaValidators1, - 1: ecdsaValidators2, - }) + testCache( + t, + testCase{height: 0, expected: ecdsaValidators1}, + testCase{height: 1, expected: ecdsaValidators2}, + ) // make sure ecdsaValidators2 is loaded at the end for LRU cache store.validatorSetCache.Get(1) @@ -518,10 +525,11 @@ func TestContractValidatorStore_CacheChange(t *testing.T) { store.saveToValidatorSetCache(2, blsValidators), ) - testCache(t, map[uint64]validators.Validators{ - 1: ecdsaValidators2, - 2: blsValidators, - }) + testCache( + t, + testCase{height: 1, expected: ecdsaValidators2}, + testCase{height: 2, expected: blsValidators}, + ) } func TestContractValidatorStore_NoCache(t *testing.T) {