Skip to content

Commit 59d2ecb

Browse files
Fix: forging int
1 parent 40a45a4 commit 59d2ecb

File tree

4 files changed

+94
-6
lines changed

4 files changed

+94
-6
lines changed

cmd/tezgen/template/contract.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ func (contract *{{$.TypeName}}) Get{{ $value.Type }}(ctx context.Context, page P
202202
}
203203
values := make([]{{ $value.Type }}, 0)
204204
for i := range operations {
205-
if operations[i].Parameters == nil {
205+
if operations[i].Parameter == nil {
206206
continue
207207
}
208208
var value {{ $value.Type }}
209-
if err := json.Unmarshal(operations[i].Parameters.Value, &value); err != nil {
209+
if err := json.Unmarshal(operations[i].Parameter.Value, &value); err != nil {
210210
return nil, err
211211
}
212212
values = append(values, value)
@@ -237,7 +237,7 @@ func getLimits(p Page) Page {
237237
return newPage
238238
}
239239

240-
func getTransactions(ctx context.Context, tzktAPI *api.API, entrypoint, contract string, page Page) ([]api.Operation, error) {
240+
func getTransactions(ctx context.Context, tzktAPI *api.API, entrypoint, contract string, page Page) ([]api.Transaction, error) {
241241
limits := getLimits(page)
242242
return tzktAPI.GetTransactions(ctx, map[string]string{
243243
"entrypoint": entrypoint,

tools/forge/opg_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package forge
2+
3+
import (
4+
"encoding/hex"
5+
"testing"
6+
7+
"github.com/dipdup-net/go-lib/node"
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestOPG(t *testing.T) {
12+
tests := []struct {
13+
name string
14+
branch string
15+
operations []node.Operation
16+
want string
17+
wantErr bool
18+
}{
19+
{
20+
name: "test 1",
21+
branch: "BLRYV1w71DtjyDU27e2XWZ2KyfcGupo985qvphm7PSCNZXk6SHL",
22+
operations: []node.Operation{
23+
{
24+
Kind: node.KindTransaction,
25+
Body: node.Transaction{
26+
Amount: "1000",
27+
Counter: "393218",
28+
Destination: "tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm",
29+
Fee: "351",
30+
GasLimit: "1521",
31+
Source: "tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm",
32+
StorageLimit: "100",
33+
},
34+
},
35+
{
36+
Kind: node.KindTransaction,
37+
Body: node.Transaction{
38+
Amount: "1000",
39+
Counter: "393219",
40+
Destination: "tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm",
41+
Fee: "351",
42+
GasLimit: "1521",
43+
Source: "tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm",
44+
StorageLimit: "100",
45+
},
46+
},
47+
{
48+
Kind: node.KindTransaction,
49+
Body: node.Transaction{
50+
Amount: "1000",
51+
Counter: "393220",
52+
Destination: "tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm",
53+
Fee: "351",
54+
GasLimit: "1521",
55+
Source: "tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm",
56+
StorageLimit: "100",
57+
},
58+
},
59+
},
60+
want: "5db044c1a354b21ef464a61febad3c4efc910588e8f9400d82a64626966af7506c00e8b36c80efb51ec85a14562426049aa182a3ce38df02828018f10b64e8070000e8b36c80efb51ec85a14562426049aa182a3ce38006c00e8b36c80efb51ec85a14562426049aa182a3ce38df02838018f10b64e8070000e8b36c80efb51ec85a14562426049aa182a3ce38006c00e8b36c80efb51ec85a14562426049aa182a3ce38df02848018f10b64e8070000e8b36c80efb51ec85a14562426049aa182a3ce3800",
61+
},
62+
}
63+
for _, tt := range tests {
64+
t.Run(tt.name, func(t *testing.T) {
65+
got, err := OPG(tt.branch, tt.operations...)
66+
if (err != nil) != tt.wantErr {
67+
t.Errorf("OPG() error = %v, wantErr %v", err, tt.wantErr)
68+
return
69+
}
70+
gotHex := hex.EncodeToString(got)
71+
assert.Equal(t, tt.want, gotHex)
72+
})
73+
}
74+
}

tools/types/bigint.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ func NewBigInt(val int64) *BigInt {
1919

2020
// NewBigIntFromString -
2121
func NewBigIntFromString(val string) *BigInt {
22-
b := big.NewInt(0)
23-
b, _ = b.SetString(val, 10)
22+
if value, ok := big.NewInt(0).SetString(val, 10); ok {
23+
return &BigInt{
24+
Int: value,
25+
}
26+
}
2427
return &BigInt{
25-
Int: b,
28+
Int: big.NewInt(0),
2629
}
2730
}
2831

tzkt/api/accounts.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package api
2+
3+
import (
4+
"context"
5+
"fmt"
6+
)
7+
8+
// AccountCounter - Returns account counter
9+
func (tzkt *API) AccountCounter(ctx context.Context, address string) (uint64, error) {
10+
return tzkt.count(ctx, fmt.Sprintf("/v1/accounts/%s/counter", address))
11+
}

0 commit comments

Comments
 (0)