Skip to content

Commit 7294eed

Browse files
committed
Fix inputSize check and ipo bid payload handling.
1 parent bb5fa15 commit 7294eed

File tree

7 files changed

+26
-25
lines changed

7 files changed

+26
-25
lines changed

general-service/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ General-purpose aggregation service. Currently provides IPO bid transaction aggr
8787
2. Derives smart contract addresses from contract indices (contract index in lower 32 bits of the 256-bit public key, remaining bits zeroed).
8888
3. Gets current epoch tick bounds from status-service (`GetTickIntervals`), cached with configurable TTL.
8989
4. For each identity, queries archive-query-service (`GetTransactionsForIdentity`) with destination = SC address, tick range = current epoch, amount = 0.
90-
5. Filters results by `input_size == 10` and `amount == 0` to isolate IPO bid transactions.
91-
6. Parses `input_data` (base64) as `ContractIPOBid`: price (int64 LE, 8 bytes) + quantity (uint16 LE, 2 bytes).
90+
5. Filters results by `input_size == 16` and `amount == 0` to isolate IPO bid transactions.
91+
6. Parses `input_data` (base64) as `ContractIPOBid`: price (int64 LE, 8 bytes) + quantity (uint16 LE, 2 bytes) + padding (6 bytes).
9292

9393
### Identity Balances
9494

general-service/clients/query_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (qsc *QueryServiceClient) GetIPOBidTransactionsForIdentity(
5959
}
6060

6161
for _, tx := range resp.Transactions {
62-
if tx.InputSize != 10 || tx.Amount != 0 {
62+
if tx.InputSize != 16 || tx.Amount != 0 {
6363
continue
6464
}
6565

general-service/clients/query_service_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
func makeBidInputData(price int64, quantity uint16) string {
20-
var buf [10]byte
20+
var buf [16]byte
2121
binary.LittleEndian.PutUint64(buf[0:8], uint64(price))
2222
binary.LittleEndian.PutUint16(buf[8:10], quantity)
2323
return base64.StdEncoding.EncodeToString(buf[:])
@@ -46,7 +46,7 @@ func TestGetIPOBidTransactionsForIdentity_SinglePage(t *testing.T) {
4646
TickNumber: 500,
4747
Timestamp: 12345,
4848
InputType: 1,
49-
InputSize: 10,
49+
InputSize: 16,
5050
InputData: inputData,
5151
Signature: "sig",
5252
MoneyFlew: true,
@@ -74,9 +74,9 @@ func TestGetIPOBidTransactionsForIdentity_FiltersOutNonBidTransactions(t *testin
7474
mock.EXPECT().GetTransactionsForIdentity(ctx, gomock.Any()).Return(&queryProto.GetTransactionsForIdentityResponse{
7575
Hits: &queryProto.Hits{Total: 4},
7676
Transactions: []*queryProto.Transaction{
77-
{Hash: "valid", InputSize: 10, Amount: 0, InputData: inputData},
77+
{Hash: "valid", InputSize: 16, Amount: 0, InputData: inputData},
7878
{Hash: "wrong_size", InputSize: 8, Amount: 0, InputData: "garbage"},
79-
{Hash: "wrong_amount", InputSize: 10, Amount: 100, InputData: inputData},
79+
{Hash: "wrong_amount", InputSize: 16, Amount: 100, InputData: inputData},
8080
{Hash: "both_wrong", InputSize: 5, Amount: 50, InputData: "garbage"},
8181
},
8282
}, nil)
@@ -97,15 +97,15 @@ func TestGetIPOBidTransactionsForIdentity_Pagination(t *testing.T) {
9797
page1Txs := make([]*queryProto.Transaction, 1000)
9898
for i := range page1Txs {
9999
page1Txs[i] = &queryProto.Transaction{
100-
Hash: fmt.Sprintf("tx_%d", i), InputSize: 10, InputData: inputData,
100+
Hash: fmt.Sprintf("tx_%d", i), InputSize: 16, InputData: inputData,
101101
}
102102
}
103103

104104
// Second page: 500 results
105105
page2Txs := make([]*queryProto.Transaction, 500)
106106
for i := range page2Txs {
107107
page2Txs[i] = &queryProto.Transaction{
108-
Hash: fmt.Sprintf("tx_%d", 1000+i), InputSize: 10, InputData: inputData,
108+
Hash: fmt.Sprintf("tx_%d", 1000+i), InputSize: 16, InputData: inputData,
109109
}
110110
}
111111

general-service/domain/contracts.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ func ParseBidInputData(inputData string) (IpoBid, error) {
2727
return IpoBid{}, fmt.Errorf("decoding base64 input data: %w", err)
2828
}
2929

30-
if len(data) != 10 {
31-
return IpoBid{}, fmt.Errorf("unexpected input data size: got %d, expected 10", len(data))
30+
if len(data) != 16 {
31+
return IpoBid{}, fmt.Errorf("unexpected input data size: got %d, expected 16", len(data))
3232
}
3333

3434
price := int64(binary.LittleEndian.Uint64(data[0:8]))
3535
quantity := binary.LittleEndian.Uint16(data[8:10])
36+
// bytes 10-15 are struct padding, discarded
3637

3738
return IpoBid{
3839
Price: price,

general-service/domain/contracts_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestContractIndexToAddress_KnownAddresses(t *testing.T) {
6161

6262
func TestParseBidInputData(t *testing.T) {
6363
t.Run("valid data", func(t *testing.T) {
64-
var buf [10]byte
64+
var buf [16]byte
6565
binary.LittleEndian.PutUint64(buf[0:8], uint64(1000))
6666
binary.LittleEndian.PutUint16(buf[8:10], 5)
6767
encoded := base64.StdEncoding.EncodeToString(buf[:])
@@ -73,7 +73,7 @@ func TestParseBidInputData(t *testing.T) {
7373
})
7474

7575
t.Run("max values", func(t *testing.T) {
76-
var buf [10]byte
76+
var buf [16]byte
7777
binary.LittleEndian.PutUint64(buf[0:8], ^uint64(0)>>1) // max int64
7878
binary.LittleEndian.PutUint16(buf[8:10], 0xFFFF)
7979
encoded := base64.StdEncoding.EncodeToString(buf[:])
@@ -98,7 +98,7 @@ func TestParseBidInputData(t *testing.T) {
9898
})
9999

100100
t.Run("wrong length long", func(t *testing.T) {
101-
encoded := base64.StdEncoding.EncodeToString(make([]byte, 12))
101+
encoded := base64.StdEncoding.EncodeToString(make([]byte, 20))
102102
_, err := ParseBidInputData(encoded)
103103
assert.Error(t, err)
104104
assert.Contains(t, err.Error(), "unexpected input data size")

general-service/grpc/service_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestGetCurrentIpoBids_Success(t *testing.T) {
4242
TickNumber: 500,
4343
Timestamp: 12345,
4444
InputType: 1,
45-
InputSize: 10,
45+
InputSize: 16,
4646
InputData: "data",
4747
Signature: "sig",
4848
MoneyFlew: true,
@@ -70,7 +70,7 @@ func TestGetCurrentIpoBids_Success(t *testing.T) {
7070
assert.Equal(t, uint32(500), tx.TickNumber)
7171
assert.Equal(t, uint64(12345), tx.Timestamp)
7272
assert.Equal(t, uint32(1), tx.InputType)
73-
assert.Equal(t, uint32(10), tx.InputSize)
73+
assert.Equal(t, uint32(16), tx.InputSize)
7474
assert.Equal(t, "data", tx.InputData)
7575
assert.Equal(t, "sig", tx.Signature)
7676
assert.True(t, tx.MoneyFlew)

general-service/test/integration/integration_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func startServer(t *testing.T, register func(s *grpc.Server)) *grpc.ClientConn {
146146
// ---------------------------------------------------------------------------
147147

148148
func makeBidInputData(price int64, quantity uint16) string {
149-
var buf [10]byte
149+
var buf [16]byte
150150
binary.LittleEndian.PutUint64(buf[0:8], uint64(price))
151151
binary.LittleEndian.PutUint16(buf[8:10], quantity)
152152
return base64.StdEncoding.EncodeToString(buf[:])
@@ -183,7 +183,7 @@ func TestIntegration_CorrectQueryParameters(t *testing.T) {
183183

184184
env.fakeQuery.responses[identity] = &queryProto.GetTransactionsForIdentityResponse{
185185
Hits: &queryProto.Hits{Total: 1},
186-
Transactions: []*queryProto.Transaction{{Hash: "h1", InputSize: 10, Amount: 0, InputData: makeBidInputData(42, 1)}},
186+
Transactions: []*queryProto.Transaction{{Hash: "h1", InputSize: 16, Amount: 0, InputData: makeBidInputData(42, 1)}},
187187
}
188188

189189
_, err = env.bidService.GetCurrentIPOBidTransactions(ctx, []string{identity})
@@ -245,14 +245,14 @@ func TestIntegration_EndToEnd(t *testing.T) {
245245
env.fakeQuery.responses[id1] = &queryProto.GetTransactionsForIdentityResponse{
246246
Hits: &queryProto.Hits{Total: 1},
247247
Transactions: []*queryProto.Transaction{
248-
{Hash: "tx1", InputSize: 10, Amount: 0, Source: id1, Destination: addr5, TickNumber: 200, InputData: makeBidInputData(100, 2), MoneyFlew: true},
249-
{Hash: "tx2", InputSize: 10, Amount: 0, Source: id1, Destination: addr7, TickNumber: 300, InputData: makeBidInputData(200, 3), MoneyFlew: true},
248+
{Hash: "tx1", InputSize: 16, Amount: 0, Source: id1, Destination: addr5, TickNumber: 200, InputData: makeBidInputData(100, 2), MoneyFlew: true},
249+
{Hash: "tx2", InputSize: 16, Amount: 0, Source: id1, Destination: addr7, TickNumber: 300, InputData: makeBidInputData(200, 3), MoneyFlew: true},
250250
},
251251
}
252252
env.fakeQuery.responses[id2] = &queryProto.GetTransactionsForIdentityResponse{
253253
Hits: &queryProto.Hits{Total: 1},
254254
Transactions: []*queryProto.Transaction{
255-
{Hash: "tx3", InputSize: 10, Amount: 0, Source: id2, Destination: addr5, TickNumber: 400, InputData: makeBidInputData(50, 1), MoneyFlew: false},
255+
{Hash: "tx3", InputSize: 16, Amount: 0, Source: id2, Destination: addr5, TickNumber: 400, InputData: makeBidInputData(50, 1), MoneyFlew: false},
256256
},
257257
}
258258

@@ -264,7 +264,7 @@ func TestIntegration_EndToEnd(t *testing.T) {
264264
// the fake returns the same response regardless of destination filter.
265265
// Note: in a real scenario the upstream would filter by destination, but our fake
266266
// returns all configured transactions for the identity. The client does post-filter
267-
// by InputSize==10 && Amount==0, which all pass here.
267+
// by InputSize==16 && Amount==0, which all pass here.
268268
alphaIPO := result[0]
269269
assert.Equal(t, "ALPHA", alphaIPO.AssetName)
270270
assert.Equal(t, uint32(5), alphaIPO.ContractIndex)
@@ -313,12 +313,12 @@ func TestIntegration_PostFiltering(t *testing.T) {
313313
env.fakeQuery.responses[identity] = &queryProto.GetTransactionsForIdentityResponse{
314314
Hits: &queryProto.Hits{Total: 3},
315315
Transactions: []*queryProto.Transaction{
316-
// Valid bid: InputSize==10, Amount==0.
317-
{Hash: "valid", InputSize: 10, Amount: 0, InputData: makeBidInputData(42, 1)},
316+
// Valid bid: InputSize==16, Amount==0.
317+
{Hash: "valid", InputSize: 16, Amount: 0, InputData: makeBidInputData(42, 1)},
318318
// Wrong InputSize.
319319
{Hash: "wrong_size", InputSize: 8, Amount: 0, InputData: "AAAAAAAAAAAAAAAA"},
320320
// Non-zero Amount.
321-
{Hash: "wrong_amount", InputSize: 10, Amount: 100, InputData: makeBidInputData(99, 2)},
321+
{Hash: "wrong_amount", InputSize: 16, Amount: 100, InputData: makeBidInputData(99, 2)},
322322
},
323323
}
324324

0 commit comments

Comments
 (0)