Skip to content

Commit

Permalink
Fix NFT mock detector test and enhance implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jetlum committed Nov 29, 2024
1 parent eb5a500 commit 21153b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 5 additions & 3 deletions mock/nft_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ func (m *MockNFTDetector) IsNFTTransaction(tx *types.Transaction) bool {
return m.IsNFTTransactionFunc(tx)
}

// Default implementation using known contracts
if tx.To() == nil {
return false
}

isContract, exists := m.knownContracts.Load(*tx.To())
return exists && isContract.(bool)
if val, exists := m.knownContracts.Load(*tx.To()); exists {
return val.(bool)
}

return false
}

// Helper methods for testing
Expand Down
16 changes: 14 additions & 2 deletions mock/nft_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,27 @@ func TestMockNFTDetector(t *testing.T) {
address := common.HexToAddress("0xBAYC")
detector.AddKnownContract(address)

// Create transaction to the known contract address
tx := types.NewTransaction(
0,
address, // Remove & operator, use Address directly
address,
big.NewInt(0),
21000,
big.NewInt(1),
nil,
)

// Add debug assertions
toAddr := tx.To()
if toAddr == nil {
t.Fatal("Transaction To address is nil")
}

// Verify the addresses match
assert.Equal(t, address, *toAddr, "Transaction address should match known contract")

// Check if transaction is detected as NFT
result := detector.IsNFTTransaction(tx)
assert.True(t, result)
assert.True(t, result, "Transaction to known NFT contract address should return true")
})
}

0 comments on commit 21153b9

Please sign in to comment.