@@ -382,6 +382,63 @@ func TestGetMetrics(t *testing.T) {
382
382
require .InEpsilon (t , 3700000 , metrics .SizeMemoryCache , 0.25 )
383
383
}
384
384
385
+ func TestGetPinnedMetrics (t * testing.T ) {
386
+ cache , cleanup := withCache (t )
387
+ defer cleanup ()
388
+
389
+ // GetMetrics 1
390
+ metrics , err := GetPinnedMetrics (cache )
391
+ require .NoError (t , err )
392
+ assert .Equal (t , & types.PinnedMetrics {PerModule : make (map [string ]types.PerModuleMetrics , 0 )}, metrics )
393
+
394
+ // Store contract 1
395
+ wasm , err := os .ReadFile ("../../testdata/hackatom.wasm" )
396
+ require .NoError (t , err )
397
+ checksum , err := StoreCode (cache , wasm )
398
+ require .NoError (t , err )
399
+
400
+ err = Pin (cache , checksum )
401
+ require .NoError (t , err )
402
+
403
+ // Store contract 2
404
+ cyberpunkWasm , err := os .ReadFile ("../../testdata/cyberpunk.wasm" )
405
+ require .NoError (t , err )
406
+ cyberpunkChecksum , err := StoreCode (cache , cyberpunkWasm )
407
+ require .NoError (t , err )
408
+
409
+ err = Pin (cache , cyberpunkChecksum )
410
+ require .NoError (t , err )
411
+
412
+ checksumStr := types .Checksum (checksum ).EncodeHex ()
413
+ cyberpunkChecksumStr := types .Checksum (cyberpunkChecksum ).EncodeHex ()
414
+
415
+ // GetMetrics 2
416
+ metrics , err = GetPinnedMetrics (cache )
417
+ require .NoError (t , err )
418
+ assert .Equal (t , len (metrics .PerModule ), 2 )
419
+ assert .Equal (t , metrics .PerModule [checksumStr ].Hits , 0 )
420
+ assert .Equal (t , metrics .PerModule [cyberpunkChecksumStr ].Hits , 0 )
421
+
422
+ // Instantiate 1
423
+ gasMeter := NewMockGasMeter (TESTING_GAS_LIMIT )
424
+ igasMeter := types .GasMeter (gasMeter )
425
+ store := NewLookup (gasMeter )
426
+ api := NewMockAPI ()
427
+ querier := DefaultQuerier (MOCK_CONTRACT_ADDR , types.Array [types.Coin ]{types .NewCoin (100 , "ATOM" )})
428
+ env := MockEnvBin (t )
429
+ info := MockInfoBin (t , "creator" )
430
+ msg1 := []byte (`{"verifier": "fred", "beneficiary": "bob"}` )
431
+ _ , _ , err = Instantiate (cache , checksum , env , info , msg1 , & igasMeter , store , api , & querier , TESTING_GAS_LIMIT , TESTING_PRINT_DEBUG )
432
+ require .NoError (t , err )
433
+
434
+ // GetMetrics 3
435
+ metrics , err = GetPinnedMetrics (cache )
436
+ require .NoError (t , err )
437
+ assert .Equal (t , len (metrics .PerModule ), 1 )
438
+ assert .Equal (t , metrics .PerModule [checksumStr ].Hits , 1 )
439
+ assert .Equal (t , metrics .PerModule [cyberpunkChecksumStr ].Hits , 0 )
440
+ }
441
+
385
442
func TestInstantiate (t * testing.T ) {
386
443
cache , cleanup := withCache (t )
387
444
defer cleanup ()
0 commit comments