@@ -28,4 +28,38 @@ describe("HlOracle", function () {
28
28
expect ( await oracle . checkUpkeep ( '0x' ) ) . to . deep . equal ( [ true , '0x' ] ) ;
29
29
await expect ( oracle . performUpkeep ( '0x' ) ) . to . emit ( oracle , 'Settled' ) ;
30
30
} ) ;
31
+
32
+ it ( "should assign prices for missed days correctly" , async function ( ) {
33
+ const { oracle, aggregator } = await loadFixture ( deployFixture ) ;
34
+ //30000, 32000
35
+ await aggregator . setLatestResponse ( "0x00000000000000000000000000000000000000000000065a4da25d3016c000000000000000000000000000000000000000000000000006c6b935b8bbd4000000" ) ;
36
+ expect ( await oracle . checkUpkeep ( '0x' ) ) . to . deep . equal ( [ true , '0x' ] ) ;
37
+ await expect ( oracle . performUpkeep ( '0x' ) ) . to . emit ( oracle , 'Settled' ) ;
38
+
39
+ // Move time forward by 3 days
40
+ await ethers . provider . send ( "evm_increaseTime" , [ 3 * 86400 ] ) ;
41
+ await ethers . provider . send ( "evm_mine" , [ ] ) ;
42
+
43
+ const latestExpiryUpdated0 = await oracle . latestExpiryUpdated ( ) ;
44
+
45
+ //27000, 35000
46
+ await aggregator . setLatestResponse ( "0x0000000000000000000000000000000000000000000005b7ac4553de7ae000000000000000000000000000000000000000000000000007695a92c20d6fe00000" ) ;
47
+ expect ( await oracle . checkUpkeep ( '0x' ) ) . to . deep . equal ( [ true , '0x' ] ) ;
48
+ await expect ( oracle . performUpkeep ( '0x' ) ) . to . emit ( oracle , 'Settled' ) ;
49
+
50
+ for ( let i = 1 ; i < 3 ; i ++ ) {
51
+ const missedExpiry = latestExpiryUpdated0 . toNumber ( ) + i * 86400 ;
52
+ const missedPrice0 = await oracle . settlePrices ( missedExpiry , 0 ) ;
53
+ const missedPrice1 = await oracle . settlePrices ( missedExpiry , 1 ) ;
54
+
55
+ expect ( missedPrice0 ) . to . be . equal ( parseEther ( ( 30000 - 1000 * i ) . toString ( ) ) ) ;
56
+ expect ( missedPrice1 ) . to . be . equal ( parseEther ( ( 32000 + 1000 * i ) . toString ( ) ) ) ;
57
+ }
58
+ const latestExpiryUpdated1 = await oracle . latestExpiryUpdated ( ) ;
59
+ expect ( latestExpiryUpdated1 ) . to . be . equal ( latestExpiryUpdated0 . toNumber ( ) + 3 * 86400 ) ;
60
+ const settlePrice0 = await oracle . settlePrices ( latestExpiryUpdated1 , 0 ) ;
61
+ const settlePrice1 = await oracle . settlePrices ( latestExpiryUpdated1 , 1 ) ;
62
+ expect ( settlePrice0 ) . to . be . equal ( parseEther ( '27000' ) ) ;
63
+ expect ( settlePrice1 ) . to . be . equal ( parseEther ( '35000' ) ) ;
64
+ } ) ;
31
65
} ) ;
0 commit comments