-
Notifications
You must be signed in to change notification settings - Fork 1
/
provider_test.go
46 lines (42 loc) · 5.41 KB
/
provider_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package price
import (
"context"
"encoding/hex"
"testing"
"github.com/evaafi/evaa-go-sdk/config"
)
func TestParse(t *testing.T) {
data := "0x7b22737461747573223a226f6b222c2274696d657374616d70223a313733303535393232392c227061636b6564507269636573223a22623565653963373234313032313230313030303139643030303130393637323633636664633030313032303132303032303930323031323030333036303230313230303430353030346462663734383433336663626363316163373565353437393866623963646664386433363862386436616533303932663463323931636638343635353930663762313461303234353532663439353030303464626636363237633565616637353065313565363839303036613138663133363133306661326236383734613632653537663963353239626334336366616534396365613032356530643864306230303230313230303730383030346462663532616364316432313063383965363036343537333266626431663535356638343365306235346135663133303565303835623538336663313639613133613061303236323632346366393030303462626635376634323439393832363837613239373461666264613533336564656132396562653463656565313333633738366631323435396338313033643937663232383931353266323866303032303132303061306630323031323030623065303230313230306330643030346262663066363435623161313434323030383431333437646436613962333863336163373931646562623738333465303362623838363233383339353936303766313930656536623465376530303034646266333164653933356536326133643430333733656531646538316338396631333261373539653039343133333731663338616234303134373935393037303063393430353434643031636565303030346262663637306632643034366333326632623139343935386162643336623763373163643131386563363335663039393063656163383633653933353066316465363638373732633663613530303230313230313031313030346262663535323030643761376636303761366162623564646666323736343937643231356635346463373934303065376665616534316631353061353932363634663038373732633663613530303034646266343034626364346165626532653962346461633461656638336663343039393935346261336338663861623864363431386366623564636164383661663663306133623765373166346466306131653365666165222c227369676e6174757265223a226137353133383937316133316235316235373662613561393664363436343164636233666366336265653833323565366466336638353834336538636262663736653038663731636238363138616665626234366564316531376633643531653334656539653531613861363338396438306361663737316162363766343030222c22617373657473223a5b223131383736393235333730383634363134343634373939303837363237313537383035303530373435333231333036343034353633313634363733383533333337393239313633313933373338222c223931363231363637393033373633303733353633353730353537363339343333343435373931353036323332363138303032363134383936393831303336363539333032383534373637323234222c223831323033353633303232353932313933383637393033383939323532373131313132383530313830363830313236333331333533383932313732323231333532313437363437323632353135222c223539363336353436313637393637313938343730313334363437303038353538303835343336303034393639303238393537393537343130333138303934323830313130303832383931373138222c223333313731353130383538333230373930323636323437383332343936393734313036393738373030313930343938383030383538333933303839343236343233373632303335343736393434222c223233313033303931373834383631333837333732313030303433383438303738353135323339353432353638373531393339393233393732373939373333373238353236303430373639373637222c22313031333835303433323836353230333030363736303439303637333539333330343338343438333733303639313337383431383731303236353632303937393739303739353430343339393034222c223730373732313936383738353634353634363431353735313739303435353834353935323939313637363735303238323430303338353938333239393832333132313832373433393431313730222c223438383339333132383635333431303530353736353436383737393935313936373631353536353831393735393935383539363936373938363031353939303330383732353736343039343839225d2c227075626c69634b6579223a2262343034663461326562623632663236323362333730633839313839373438613032373663303731393635623136343662393936343037663130643732656239227d"
rawData, err := Parse(data)
if err != nil {
t.Fatalf("failed to unpack price data, err: %s", err)
}
if rawData.Timestamp != 1730559229 {
t.Errorf("Timestamp want %d, got %d", 1728231907, rawData.Timestamp)
}
if hex.EncodeToString(rawData.PricesDict.AsCell().Hash()) != "4df4b15afc29f24330c513d360c589da8f5fa9a3f59f319e977dfcf0a032bcff" {
t.Errorf("PricesDict want %s, got %x", "4df4b15afc29f24330c513d360c589da8f5fa9a3f59f319e977dfcf0a032bcff", rawData.PricesDict.AsCell().Hash())
}
if hex.EncodeToString(rawData.Signature) != "a75138971a31b51b576ba5a96d64641dcb3fcf3bee8325e6df3f85843e8cbbf76e08f71cb8618afebb46ed1e17f3d51e34ee9e51a8a6389d80caf771ab67f400" {
t.Errorf("Signature want %s, got %x", "a75138971a31b51b576ba5a96d64641dcb3fcf3bee8325e6df3f85843e8cbbf76e08f71cb8618afebb46ed1e17f3d51e34ee9e51a8a6389d80caf771ab67f400", rawData.Signature)
}
if hex.EncodeToString(rawData.PubKey) != "b404f4a2ebb62f2623b370c89189748a0276c071965b1646b996407f10d72eb9" {
t.Errorf("PubKey want %s, got %x", "b404f4a2ebb62f2623b370c89189748a0276c071965b1646b996407f10d72eb9", rawData.Signature)
}
for k, v := range rawData.Prices() {
t.Logf("%s: %10s", k, v.String())
}
}
func TestProvider_GetRawData(t *testing.T) {
service := newProvider(nil)
rawData, err := service.GetRawData(context.Background(), Endpoint, "0xd3a8c0b9fd44fd25a49289c631e3ac45689281f2f8cf0744400b4c65bed38e5d")
if err != nil {
t.Fatalf("failed to GetRawData, err: %s", err)
}
if !rawData.verify(config.GetMainMainnetConfig().Assets) {
t.Errorf("verify want true, got false")
}
for k, v := range rawData.Prices() {
t.Logf("%s: %10s", k, v.String())
}
}