commit inicial do projeto
This commit is contained in:
28
internal/oracle/validator_test.go
Normal file
28
internal/oracle/validator_test.go
Normal file
@ -0,0 +1,28 @@
|
||||
package oracle
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestValidateMajority(t *testing.T) {
|
||||
now := time.Now()
|
||||
d1 := &OracleData{Key: "USD-BRL", Value: 5.00, Time: now}
|
||||
d2 := &OracleData{Key: "USD-BRL", Value: 5.01, Time: now.Add(-1 * time.Minute)}
|
||||
d3 := &OracleData{Key: "USD-BRL", Value: 4.99, Time: now.Add(-2 * time.Minute)}
|
||||
|
||||
res, err := ValidateMajority([]*OracleData{d1, d2, d3}, 0.05)
|
||||
if err != nil {
|
||||
t.Fatalf("Falha ao validar maioria: %v", err)
|
||||
}
|
||||
if res == nil || res.Value == 0 {
|
||||
t.Error("Valor inválido retornado pelo consenso")
|
||||
}
|
||||
|
||||
// sem consenso
|
||||
d4 := &OracleData{Key: "USD-BRL", Value: 3.0, Time: now}
|
||||
_, err = ValidateMajority([]*OracleData{d1, d4}, 0.001)
|
||||
if err == nil {
|
||||
t.Error("Esperado erro por falta de consenso")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user