-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
112 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package priceoracle | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBuildCoingeckoReq(t *testing.T) { | ||
origTimeNow := timeNow | ||
defer func() { | ||
timeNow = origTimeNow | ||
}() | ||
|
||
// Fix the current time to 2025-01-23 10:00 UTC | ||
fixedTime := time.Date(2025, 1, 23, 10, 0, 0, 0, time.UTC) | ||
timeNow = func() time.Time { | ||
return fixedTime | ||
} | ||
|
||
// Table of test cases | ||
testCases := []struct { | ||
name string | ||
isPriceOracleFixed bool | ||
expectedDate string // we expect this to appear in the URL | ||
}{ | ||
{ | ||
name: "Fork not fixed => uses yesterday", | ||
isPriceOracleFixed: false, | ||
expectedDate: "22-01-2025", // one day before fixedTime | ||
}, | ||
{ | ||
name: "Fork fixed => uses today", | ||
isPriceOracleFixed: true, | ||
expectedDate: "23-01-2025", // same as fixedTime | ||
}, | ||
} | ||
|
||
priceFeed := &priceFeed{} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
req, err := priceFeed.buildCoingeckoReq(tc.isPriceOracleFixed) | ||
require.NoError(t, err, "building request should not fail") | ||
|
||
url := req.URL.String() | ||
require.Containsf(t, url, tc.expectedDate, | ||
"URL %q does not contain expected date %q", url, tc.expectedDate) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters