Skip to content

Commit a9e2d45

Browse files
authored
Merge pull request #41 from bandprotocol/add-data-source-page
Big patch from reasonml codebase to Rescript
2 parents 075899b + 45c27d7 commit a9e2d45

File tree

145 files changed

+6726
-6327
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+6726
-6327
lines changed

__tests__/Address_test.res

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,61 @@ open Expect
44

55
describe("Expect Address to work correctly", () => {
66
test("should be able to create address from hex", () =>
7-
expect("F23391B5DBF982E37FB7DADEA64AAE21CAE4C172" |> fromHex) |> toEqual(
7+
expect("F23391B5DBF982E37FB7DADEA64AAE21CAE4C172"->fromHex)->toEqual(
88
Address("f23391b5dbf982e37fb7dadea64aae21cae4c172"),
99
)
1010
)
1111

1212
test("should be able to create address from hex with 0x prefix", () =>
13-
expect("0xF23391B5DBF982E37FB7DADEA64AAE21CAE4C172" |> fromHex) |> toEqual(
13+
expect("0xF23391B5DBF982E37FB7DADEA64AAE21CAE4C172"->fromHex)->toEqual(
1414
Address("f23391b5dbf982e37fb7dadea64aae21cae4c172"),
1515
)
1616
)
1717

1818
test("should be able to get hexString with 0x prefix", () =>
19-
expect(fromHex("f23391b5dbf982e37fb7dadea64aae21cae4c172") |> toHex(~with0x=true)) |> toBe(
19+
expect(fromHex("f23391b5dbf982e37fb7dadea64aae21cae4c172")->toHex(~with0x=true))->toEqual(
2020
"0xf23391b5dbf982e37fb7dadea64aae21cae4c172",
2121
)
2222
)
2323

2424
test("should be able to create address from fromBech32", () =>
25-
expect("bandvaloper13zmknvkq2sj920spz90g4r9zjan8g58423y76e" |> fromBech32) |> toEqual(
25+
expect("bandvaloper13zmknvkq2sj920spz90g4r9zjan8g58423y76e"->fromBech32)->toEqual(
2626
Address("88b769b2c05424553e01115e8a8ca297667450f5"),
2727
)
2828
)
2929

3030
test("should be able to convert self to hex", () =>
31-
expect(Address("88b769b2c05424553e01115e8a8ca297667450f5") |> toHex) |> toEqual(
31+
expect(Address("88b769b2c05424553e01115e8a8ca297667450f5")->toHex)->toEqual(
3232
"88b769b2c05424553e01115e8a8ca297667450f5",
3333
)
3434
)
3535

3636
test("should be able to convert self to toOperatorBech32", () =>
37-
expect(Address("88b769b2c05424553e01115e8a8ca297667450f5") |> toOperatorBech32) |> toEqual(
37+
expect(Address("88b769b2c05424553e01115e8a8ca297667450f5")->toOperatorBech32)->toEqual(
3838
"bandvaloper13zmknvkq2sj920spz90g4r9zjan8g58423y76e",
3939
)
4040
)
4141

4242
test("should be able to convert self to toBech32", () =>
43-
expect(Address("88b769b2c05424553e01115e8a8ca297667450f5") |> toBech32) |> toEqual(
43+
expect(Address("88b769b2c05424553e01115e8a8ca297667450f5")->toBech32)->toEqual(
4444
"band13zmknvkq2sj920spz90g4r9zjan8g584x8qalj",
4545
)
4646
)
4747

4848
test("should be able to convert toBech32 to hex directly", () =>
49-
expect("band13zmknvkq2sj920spz90g4r9zjan8g584x8qalj" |> bech32ToHex) |> toEqual(
49+
expect("band13zmknvkq2sj920spz90g4r9zjan8g584x8qalj"->bech32ToHex)->toEqual(
5050
"88b769b2c05424553e01115e8a8ca297667450f5",
5151
)
5252
)
5353

5454
test("should be able to convert hex to bech32 directly", () =>
55-
expect("88b769b2c05424553e01115e8a8ca297667450f5" |> hexToBech32) |> toEqual(
55+
expect("88b769b2c05424553e01115e8a8ca297667450f5"->hexToBech32)->toEqual(
5656
"band13zmknvkq2sj920spz90g4r9zjan8g584x8qalj",
5757
)
5858
)
5959

6060
test("should be able to convert hex to hexToOperatorBech32 directly", () =>
61-
expect("88b769b2c05424553e01115e8a8ca297667450f5" |> hexToOperatorBech32) |> toEqual(
61+
expect("88b769b2c05424553e01115e8a8ca297667450f5"->hexToOperatorBech32)->toEqual(
6262
"bandvaloper13zmknvkq2sj920spz90g4r9zjan8g58423y76e",
6363
)
6464
)

__tests__/Bech32_test.res

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe("Expect Bech32 to work correctly", () => {
3939
24,
4040
14,
4141
]->fromWords,
42-
) |> toEqual([
42+
)->toEqual([
4343
75,
4444
146,
4545
150,
@@ -87,7 +87,7 @@ describe("Expect Bech32 to work correctly", () => {
8787
211,
8888
14,
8989
]->toWords,
90-
) |> toEqual([
90+
)->toEqual([
9191
9,
9292
14,
9393
9,
@@ -125,45 +125,48 @@ describe("Expect Bech32 to work correctly", () => {
125125

126126
test("should be able to encode correctly", () =>
127127
expect(
128-
[
129-
9,
130-
14,
131-
9,
132-
9,
133-
13,
134-
6,
135-
4,
136-
16,
137-
24,
138-
20,
139-
29,
140-
15,
141-
23,
142-
28,
143-
15,
144-
9,
145-
29,
146-
31,
147-
16,
148-
0,
149-
21,
150-
31,
151-
4,
152-
19,
153-
25,
154-
28,
155-
24,
156-
18,
157-
15,
158-
20,
159-
24,
160-
14,
161-
] |> encode("bandvaloper"),
162-
) |> toBe("bandvaloper1fwffdxysc5a0hu0falsq4lyneucj05cwryzfp0")
128+
encode(
129+
"bandvaloper",
130+
[
131+
9,
132+
14,
133+
9,
134+
9,
135+
13,
136+
6,
137+
4,
138+
16,
139+
24,
140+
20,
141+
29,
142+
15,
143+
23,
144+
28,
145+
15,
146+
9,
147+
29,
148+
31,
149+
16,
150+
0,
151+
21,
152+
31,
153+
4,
154+
19,
155+
25,
156+
28,
157+
24,
158+
18,
159+
15,
160+
20,
161+
24,
162+
14,
163+
],
164+
),
165+
)->toEqual("bandvaloper1fwffdxysc5a0hu0falsq4lyneucj05cwryzfp0")
163166
)
164167

165168
test("should be able to decode correctly", () =>
166-
expect("bandvaloper1fwffdxysc5a0hu0falsq4lyneucj05cwryzfp0"->decode) |> toEqual(
169+
expect("bandvaloper1fwffdxysc5a0hu0falsq4lyneucj05cwryzfp0"->decode)->toEqual(
167170
Bech32.decoded_t(
168171
~prefix="bandvaloper",
169172
~words=[

__tests__/Coin_test.res

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,43 @@ describe("Expect Coin to work correctly", () => {
99
Js.Dict.set(dict, "amount", Js.Json.string("1000000"))
1010
let coin = Js.Json.object_(dict)
1111

12-
expect(coin |> decodeCoin) |> toEqual({denom: "uband", amount: 1000000.})
12+
expect(coin->JsonUtils.Decode.mustDecode(decodeCoin))->toEqual({
13+
denom: "uband",
14+
amount: 1000000.,
15+
})
1316
})
1417

1518
test("should be able to create Coin by uband amount", () =>
16-
expect(newUBANDFromAmount(1000.)) |> toEqual({denom: "uband", amount: 1000.})
19+
expect(newUBANDFromAmount(1000.))->toEqual({denom: "uband", amount: 1000.})
1720
)
1821

1922
test("should be able to create Coin by newCoin", () =>
20-
expect(newCoin("ustake", 999.)) |> toEqual({denom: "ustake", amount: 999.})
23+
expect(newCoin("ustake", 999.))->toEqual({denom: "ustake", amount: 999.})
2124
)
2225

2326
test("should be able to getBandAmountFromCoin", () =>
24-
expect({amount: 1000000., denom: "uband"} |> getBandAmountFromCoin) |> toEqual(1.)
27+
expect({amount: 1000000., denom: "uband"}->getBandAmountFromCoin)->toEqual(1.)
2528
)
2629

2730
test("should be able to getBandAmountFromCoins", () =>
2831
expect(
2932
list{
3033
{amount: 2000000., denom: "ustake"},
3134
{amount: 3000000., denom: "uband"},
32-
} |> getBandAmountFromCoins,
33-
) |> toEqual(3.)
35+
}->getBandAmountFromCoins,
36+
)->toEqual(3.)
3437
)
3538

3639
test("should be able to getUBandAmountFromCoin", () =>
37-
expect({amount: 5000000., denom: "uband"} |> getUBandAmountFromCoin) |> toEqual(5000000.)
40+
expect({amount: 5000000., denom: "uband"}->getUBandAmountFromCoin)->toEqual(5000000.)
3841
)
3942

4043
test("should be able to getUBandAmountFromCoins", () =>
4144
expect(
4245
list{
4346
{amount: 1000000., denom: "ustake"},
4447
{amount: 2000000., denom: "uband"},
45-
} |> getUBandAmountFromCoins,
46-
) |> toEqual(2000000.)
48+
}->getUBandAmountFromCoins,
49+
)->toEqual(2000000.)
4750
)
4851
})

__tests__/ExecutableParser_test.res

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ if __name__ == "__main__":
3434
print(str(e), file=sys.stderr)
3535
sys.exit(1)
3636
`
37-
|> getVariables
38-
|> Belt.Option.getExn,
39-
) |> toEqual(list{"symbol"})
37+
->getVariables
38+
->Belt.Option.getExn,
39+
)->toEqual(["symbol"])
4040
)
41-
4241
test("test get multiple variable in python script", () =>
4342
expect(
4443
`#!/usr/bin/env python3
@@ -55,9 +54,9 @@ if __name__ == "__main__":
5554
print(str(e), file=sys.stderr)
5655
sys.exit(1)
5756
`
58-
|> getVariables
59-
|> Belt.Option.getExn,
60-
) |> toEqual(list{"symbol", "main", "temp"})
57+
->getVariables
58+
->Belt.Option.getExn,
59+
)->toEqual(["symbol", "main", "temp"])
6160
)
6261

6362
test("test main function's name closely in python script", () =>
@@ -84,28 +83,28 @@ if __name__ == "__main__":
8483
print(str(e), file=sys.stderr)
8584
sys.exit(1)
8685
`
87-
|> getVariables
88-
|> Belt.Option.getExn,
89-
) |> toEqual(list{"symbol"})
86+
->getVariables
87+
->Belt.Option.getExn,
88+
)->toEqual(["symbol"])
9089
)
9190

9291
test("test get no variable in python script", () =>
9392
expect(
9493
`#!/usr/bin/env python3
9594
96-
import json
95+
import json
9796
98-
def main():
99-
return "111"
97+
def main():
98+
return "111"
10099
101-
if __name__ == "__main__":
102-
try:
103-
print(main(*sys.argv[1:]))
104-
except Exception as e:
105-
print(str(e), file=sys.stderr)
106-
sys.exit(1)
107-
` |> getVariables,
108-
) |> toEqual(None)
100+
if __name__ == "__main__":
101+
try:
102+
print(main(*sys.argv[1:]))
103+
except Exception as e:
104+
print(str(e), file=sys.stderr)
105+
sys.exit(1)
106+
`->getVariables,
107+
)->toEqual(Some([]))
109108
)
110109

111110
test("test no main function in python script", () =>
@@ -122,24 +121,24 @@ if __name__ == "__main__":
122121
except Exception as e:
123122
print(str(e), file=sys.stderr)
124123
sys.exit(1)
125-
` |> getVariables,
126-
) |> toEqual(None)
124+
`->getVariables,
125+
)->toEqual(None)
127126
)
128127

129128
test("test parseExecutableScript(python script)", () =>
130129
expect(
131130
"IyEvdXNyL2Jpbi9lbnYgcHl0aG9uMwoKaW1wb3J0IGpzb24KaW1wb3J0IHVybGxpYi5yZXF1ZXN0CmltcG9ydCBzeXMKCkNPSU5TX1VSTCA9ICJodHRwczovL2FwaS5jb2luZ2Vja28uY29tL2FwaS92My9jb2lucy9saXN0IgpQUklDRV9VUkwgPSAiaHR0cHM6Ly9hcGkuY29pbmdlY2tvLmNvbS9hcGkvdjMvc2ltcGxlL3ByaWNlP2lkcz17fSZ2c19jdXJyZW5jaWVzPXVzZCIKCgpkZWYgbWFrZV9qc29uX3JlcXVlc3QodXJsKToKICAgIHJldHVybiBqc29uLmxvYWRzKHVybGxpYi5yZXF1ZXN0LnVybG9wZW4odXJsKS5yZWFkKCkpCgoKZGVmIG1haW4oc3ltYm9sKToKICAgIGNvaW5zID0gbWFrZV9qc29uX3JlcXVlc3QoQ09JTlNfVVJMKQogICAgZm9yIGNvaW4gaW4gY29pbnM6CiAgICAgICAgaWYgY29pblsic3ltYm9sIl0gPT0gc3ltYm9sLmxvd2VyKCk6CiAgICAgICAgICAgIHNsdWcgPSBjb2luWyJpZCJdCiAgICAgICAgICAgIHJldHVybiBtYWtlX2pzb25fcmVxdWVzdChQUklDRV9VUkwuZm9ybWF0KHNsdWcpKVtzbHVnXVsidXNkIl0KICAgIHJhaXNlIFZhbHVlRXJyb3IoInVua25vd24gQ29pbkdlY2tvIHN5bWJvbDoge30iLmZvcm1hdChzeW1ib2wpKQoKCmlmIF9fbmFtZV9fID09ICJfX21haW5fXyI6CiAgICB0cnk6CiAgICAgICAgcHJpbnQobWFpbigqc3lzLmFyZ3ZbMTpdKSkKICAgIGV4Y2VwdCBFeGNlcHRpb24gYXMgZToKICAgICAgICBwcmludChzdHIoZSksIGZpbGU9c3lzLnN0ZGVycikKICAgICAgICBzeXMuZXhpdCgxKQo="
132-
|> JsBuffer.fromBase64
133-
|> parseExecutableScript
134-
|> Belt.Option.getExn,
135-
) |> toEqual(list{"symbol"})
131+
->JsBuffer.fromBase64
132+
->parseExecutableScript
133+
->Belt.Option.getExn,
134+
)->toEqual(["symbol"])
136135
)
137136

138137
test("test parseExecutableScript return None", () =>
139138
expect(
140139
"IyEvYmluL3NoCgpzeW1ib2w9JDEyCgojIENyeXB0b2N1cnJlbmN5IHByaWNlIGVuZHBvaW50OiBodHRwczovL3d3dy5jb2luZ2Vja28uY29tL2FwaS9kb2N1bWVudGF0aW9ucy92Mwp1cmw9Imh0dHBzOi8vYXBpLmNvaW5nZWNrby5jb20vYXBpL3YzL3NpbXBsZS9wcmljZT9pZHM9JHN5bWJvbCZ2c19jdXJyZW5jaWVzPXVzZCIKCiMgUGVyZm9ybXMgZGF0YSBmZXRjaGluZyBhbmQgcGFyc2VzIHRoZSByZXN1bHQKY3VybCAtcyAtWCBHRVQgJHVybCAtSCAiYWNjZXB0OiBhcHBsaWNhdGlvbi9qc29uIiB8IGpxIC1lciAiLltcIiRzeW1ib2xcIl0udXNkIgo="
141-
|> JsBuffer.fromBase64
142-
|> parseExecutableScript,
143-
) |> toEqual(None)
140+
->JsBuffer.fromBase64
141+
->parseExecutableScript,
142+
)->toEqual(None)
144143
)
145144
})

0 commit comments

Comments
 (0)