Files
dejo-node/internal/oracle/store_test.go
2025-05-23 10:44:32 -03:00

30 lines
717 B
Go

package oracle
import "testing"
func TestStore_SaveAndGet(t *testing.T) {
s := NewStore(3)
d := &OracleData{Key: "ETH-BRL", Value: 10000.0}
s.Save(d)
if got := s.Get("ETH-BRL"); got == nil || got.Value != 10000.0 {
t.Error("falha ao buscar valor salvo")
}
}
func TestStore_History(t *testing.T) {
s := NewStore(2)
s.Save(&OracleData{Key: "ETH-BRL", Value: 1})
s.Save(&OracleData{Key: "ETH-BRL", Value: 2})
s.Save(&OracleData{Key: "ETH-BRL", Value: 3}) // deve descartar o primeiro
hist := s.History("ETH-BRL")
if len(hist) != 2 {
t.Errorf("esperado 2 entradas no histórico, obtido %d", len(hist))
}
if hist[0].Value != 2 || hist[1].Value != 3 {
t.Error("histórico não está correto")
}
}