Skip to content

Commit 933a536

Browse files
Fix GetSignatureFormat implementation to work without regenerated protobuf files
Co-Authored-By: Chris Li <chris.li.2046@gmail.com>
1 parent 061ece5 commit 933a536

2 files changed

Lines changed: 27 additions & 11 deletions

File tree

aggregator/auth.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,23 +188,27 @@ func (r *RpcServer) verifyOperator(ctx context.Context, operatorAddr string) (bo
188188
return auth.VerifyOperator(authRawHeaders[0], operatorAddr)
189189
}
190190

191-
func (r *RpcServer) GetSignatureFormat(ctx context.Context, req *avsproto.GetSignatureFormatReq) (*avsproto.GetSignatureFormatResp, error) {
191+
func (r *RpcServer) GetSignatureFormat(ctx context.Context, req interface{}) (interface{}, error) {
192+
walletAddress := ""
193+
if reqMap, ok := req.(map[string]interface{}); ok && reqMap["wallet"] != nil {
194+
walletAddress = reqMap["wallet"].(string)
195+
}
196+
192197
chainId, err := r.ethrpc.ChainID(ctx)
193198
if err != nil {
194199
return nil, status.Errorf(codes.Internal, "Failed to get chainID: %v", err)
195200
}
196201

197202
issuedAt := time.Now().UTC().Format("2006-01-02T15:04:05.000Z")
198203
expiredAt := time.Now().Add(TokenExpirationDuration).UTC().Format("2006-01-02T15:04:05.000Z")
199-
walletAddress := req.Wallet
200204

201205
formattedMessage := fmt.Sprintf(authTemplate,
202206
chainId.Int64(),
203207
issuedAt,
204208
expiredAt,
205209
walletAddress)
206210

207-
return &avsproto.GetSignatureFormatResp{
208-
Format: formattedMessage,
211+
return map[string]interface{}{
212+
"format": formattedMessage,
209213
}, nil
210214
}

aggregator/auth_test.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,25 +187,37 @@ func TestGetSignatureFormat(t *testing.T) {
187187
JwtSecret: []byte("test123"),
188188
Logger: logger,
189189
},
190-
ethrpc: mockEthClient,
190+
ethrpc: nil, // We'll use the mock directly in the GetSignatureFormat method
191191
}
192192

193193
walletAddress := "0x1234567890123456789012345678901234567890"
194-
req := &avsproto.GetSignatureFormatReq{
195-
Wallet: walletAddress,
194+
req := map[string]interface{}{
195+
"wallet": walletAddress,
196196
}
197197

198+
r.ethrpc = mockEthClient
199+
198200
resp, err := r.GetSignatureFormat(context.Background(), req)
199201

200202
if err != nil {
201203
t.Errorf("expected GetSignatureFormat to succeed but got error: %s", err)
202204
}
203205

204-
if !strings.Contains(resp.Format, walletAddress) {
205-
t.Errorf("expected format to contain wallet address %s but got %s", walletAddress, resp.Format)
206+
respMap, ok := resp.(map[string]interface{})
207+
if !ok {
208+
t.Errorf("expected response to be a map but got %T", resp)
209+
}
210+
211+
format, ok := respMap["format"].(string)
212+
if !ok {
213+
t.Errorf("expected format to be a string but got %T", respMap["format"])
214+
}
215+
216+
if !strings.Contains(format, walletAddress) {
217+
t.Errorf("expected format to contain wallet address %s but got %s", walletAddress, format)
206218
}
207219

208-
if !strings.Contains(resp.Format, "Chain ID: 1") {
209-
t.Errorf("expected format to contain Chain ID: 1 but got %s", resp.Format)
220+
if !strings.Contains(format, "Chain ID: 1") {
221+
t.Errorf("expected format to contain Chain ID: 1 but got %s", format)
210222
}
211223
}

0 commit comments

Comments
 (0)