Skip to content

Commit

Permalink
Node/Acct: Pending status query fix (wormhole-foundation#2320)
Browse files Browse the repository at this point in the history
* Node/Acct: Pending status query fix

* Node/Acct: Test should actually verify the results
  • Loading branch information
bruce-riley authored Jan 31, 2023
1 parent 15f4858 commit 4116f84
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
16 changes: 10 additions & 6 deletions node/pkg/accountant/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type (
// TransferStatus contains the status returned for a transfer.
TransferStatus struct {
Committed *TransferStatusCommitted `json:"committed"`
Pending *TransferStatusPending `json:"pending"`
Pending *[]TransferStatusPending `json:"pending"`
}

// TransferStatusCommitted contains the data returned for a committed transfer.
Expand All @@ -85,7 +85,11 @@ type (

// TransferStatusPending contains the data returned for a committed transfer.
TransferStatusPending struct {
// TODO: Fill this in once we get a sample.
Digest []byte `json:"digest"`
TxHash []byte `json:"tx_hash"`
Signatures string `json:"signatures"`
GuardianSetIndex uint32 `json:"guardian_set_index"`
EmitterChain uint16 `json:"emitter_chain"`
}
)

Expand Down Expand Up @@ -277,12 +281,12 @@ func (acct *Accountant) queryMissingObservations() ([]MissingObservation, error)
acct.logger.Debug("acctaudit: submitting missing_observations query", zap.String("query", query))
respBytes, err := acct.wormchainConn.SubmitQuery(acct.ctx, acct.contract, []byte(query))
if err != nil {
return nil, fmt.Errorf("missing_observations query failed: %w", err)
return nil, fmt.Errorf("missing_observations query failed: %w, %s", err, query)
}

var ret MissingObservationsResponse
if err := json.Unmarshal(respBytes, &ret); err != nil {
return nil, fmt.Errorf("failed to parse missing_observations response: %w", err)
return nil, fmt.Errorf("failed to parse missing_observations response: %w, resp: %s", err, string(respBytes))
}

acct.logger.Debug("acctaudit: missing_observations query response", zap.Int("numEntries", len(ret.Missing)), zap.String("result", string(respBytes)))
Expand All @@ -300,12 +304,12 @@ func (acct *Accountant) queryBatchTransferStatus(keys []TransferKey) (map[string
acct.logger.Debug("acctaudit: submitting batch_transfer_status query", zap.String("query", query))
respBytes, err := acct.wormchainConn.SubmitQuery(acct.ctx, acct.contract, []byte(query))
if err != nil {
return nil, fmt.Errorf("batch_transfer_status query failed: %w", err)
return nil, fmt.Errorf("batch_transfer_status query failed: %w, %s", err, query)
}

var response BatchTransferStatusResponse
if err := json.Unmarshal(respBytes, &response); err != nil {
return nil, fmt.Errorf("failed to unmarshal response: %w", err)
return nil, fmt.Errorf("failed to unmarshal response: %w, resp: %s", err, string(respBytes))
}

ret := make(map[string]*TransferStatus)
Expand Down
37 changes: 36 additions & 1 deletion node/pkg/accountant/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,40 @@ func TestParseBatchTransferStatusNotFoundResponse(t *testing.T) {
}

func TestParseBatchTransferStatusPendingResponse(t *testing.T) {
//TODO: Write this test once we get a sample response.
responsesJson := []byte("{\"details\":[{\"key\":{\"emitter_chain\":2,\"emitter_address\":\"0000000000000000000000000290fb167208af455bb137780163b7b7a9a10c16\",\"sequence\":3},\"status\":{\"pending\":[{\"digest\":\"65hmAN4IbW9MBnSDzYmgoD/3ze+F8ik9NGeKR/vQ4J4=\",\"tx_hash\":\"CjHx8zExnr4JU8ewAu5/tXM6a5QyslKufGHZNSr0aE8=\",\"signatures\":\"1\",\"guardian_set_index\":0,\"emitter_chain\":2}]}}]}")
var response BatchTransferStatusResponse
err := json.Unmarshal(responsesJson, &response)
require.NoError(t, err)
require.Equal(t, 1, len(response.Details))

expectedEmitterAddress, err := vaa.StringToAddress("0000000000000000000000000290fb167208af455bb137780163b7b7a9a10c16")
require.NoError(t, err)

expectedDigest, err := hex.DecodeString("eb986600de086d6f4c067483cd89a0a03ff7cdef85f2293d34678a47fbd0e09e")
require.NoError(t, err)

expectedTxHash, err := hex.DecodeString("0a31f1f331319ebe0953c7b002ee7fb5733a6b9432b252ae7c61d9352af4684f")
require.NoError(t, err)

expectedResult := TransferDetails{
Key: TransferKey{
EmitterChain: uint16(vaa.ChainIDEthereum),
EmitterAddress: expectedEmitterAddress,
Sequence: 3,
},
Status: &TransferStatus{
Pending: &[]TransferStatusPending{
TransferStatusPending{
Digest: expectedDigest,
TxHash: expectedTxHash,
Signatures: "1",
GuardianSetIndex: 0,
EmitterChain: uint16(vaa.ChainIDEthereum),
},
},
},
}

// Use DeepEqual() because the response contains pointers.
assert.True(t, reflect.DeepEqual(expectedResult, response.Details[0]))
}

0 comments on commit 4116f84

Please sign in to comment.