Skip to content

Commit 21153b9

Browse files
committed
Fix NFT mock detector test and enhance implementation
1 parent eb5a500 commit 21153b9

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

mock/nft_mock.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ func (m *MockNFTDetector) IsNFTTransaction(tx *types.Transaction) bool {
4040
return m.IsNFTTransactionFunc(tx)
4141
}
4242

43-
// Default implementation using known contracts
4443
if tx.To() == nil {
4544
return false
4645
}
4746

48-
isContract, exists := m.knownContracts.Load(*tx.To())
49-
return exists && isContract.(bool)
47+
if val, exists := m.knownContracts.Load(*tx.To()); exists {
48+
return val.(bool)
49+
}
50+
51+
return false
5052
}
5153

5254
// Helper methods for testing

mock/nft_mock_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,27 @@ func TestMockNFTDetector(t *testing.T) {
1717
address := common.HexToAddress("0xBAYC")
1818
detector.AddKnownContract(address)
1919

20+
// Create transaction to the known contract address
2021
tx := types.NewTransaction(
2122
0,
22-
address, // Remove & operator, use Address directly
23+
address,
2324
big.NewInt(0),
2425
21000,
2526
big.NewInt(1),
2627
nil,
2728
)
29+
30+
// Add debug assertions
31+
toAddr := tx.To()
32+
if toAddr == nil {
33+
t.Fatal("Transaction To address is nil")
34+
}
35+
36+
// Verify the addresses match
37+
assert.Equal(t, address, *toAddr, "Transaction address should match known contract")
38+
39+
// Check if transaction is detected as NFT
2840
result := detector.IsNFTTransaction(tx)
29-
assert.True(t, result)
41+
assert.True(t, result, "Transaction to known NFT contract address should return true")
3042
})
3143
}

0 commit comments

Comments
 (0)