feat: Handle Status Mint transaction (#4137)
This commit is contained in:
parent
653df822da
commit
5674a010cd
|
@ -16,6 +16,7 @@ import (
|
|||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -748,6 +749,65 @@ func TestGetActivityEntriesFilterByType(t *testing.T) {
|
|||
require.Equal(t, 5, len(entries))
|
||||
}
|
||||
|
||||
func TestStatusMintCustomEvent(t *testing.T) {
|
||||
deps, close := setupTestActivityDB(t)
|
||||
defer close()
|
||||
|
||||
td, fromTds, toTds := fillTestData(t, deps.db)
|
||||
trs, fromTrs, toTrs := transfer.GenerateTestTransfers(t, deps.db, td.nextIndex, 3)
|
||||
|
||||
allAddresses := append(append(append(fromTds, toTds...), fromTrs...), toTrs...)
|
||||
|
||||
trs[0].From = eth.HexToAddress("0x0")
|
||||
transfer.InsertTestTransferWithOptions(t, deps.db, trs[0].To, &trs[0], &transfer.TestTransferOptions{
|
||||
TokenAddress: eth.HexToAddress("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"),
|
||||
Receipt: &types.Receipt{
|
||||
Logs: []*types.Log{
|
||||
{Topics: []eth.Hash{eth.HexToHash("0xea667487ed28493de38fd2808b00affaee21d875a9e95aa01ef8352151292297")}},
|
||||
{Topics: []eth.Hash{eth.HexToHash("0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925")}},
|
||||
},
|
||||
},
|
||||
})
|
||||
// StatusMint - 0x28c427b0611d99da5c4f7368abe57e86b045b483c4689ae93e90745802335b87
|
||||
trs[1].From = eth.HexToAddress("0x0")
|
||||
transfer.InsertTestTransferWithOptions(t, deps.db, trs[1].To, &trs[1], &transfer.TestTransferOptions{
|
||||
TokenAddress: eth.HexToAddress("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb49"),
|
||||
Receipt: &types.Receipt{
|
||||
Logs: []*types.Log{
|
||||
{Topics: []eth.Hash{eth.HexToHash("0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925")}},
|
||||
{Topics: []eth.Hash{eth.HexToHash("0x28c427b0611d99da5c4f7368abe57e86b045b483c4689ae93e90745802335b87")}},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// Log order should not matter
|
||||
trs[2].From = eth.HexToAddress("0x0")
|
||||
transfer.InsertTestTransferWithOptions(t, deps.db, trs[2].To, &trs[2], &transfer.TestTransferOptions{
|
||||
TokenAddress: eth.HexToAddress("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb49"),
|
||||
Receipt: &types.Receipt{
|
||||
Logs: []*types.Log{
|
||||
{Topics: []eth.Hash{eth.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")}},
|
||||
{Topics: []eth.Hash{eth.HexToHash("0x28c427b0611d99da5c4f7368abe57e86b045b483c4689ae93e90745802335b87")}},
|
||||
{Topics: []eth.Hash{eth.HexToHash("0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925")}},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
var filter Filter
|
||||
|
||||
entries, err := getActivityEntries(context.Background(), deps, allAddresses, true, []common.ChainID{}, filter, 0, 15)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 7, len(entries))
|
||||
|
||||
filter.Types = []Type{MintAT}
|
||||
|
||||
entries, err = getActivityEntries(context.Background(), deps, allAddresses, true, []common.ChainID{}, filter, 0, 15)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 2, len(entries))
|
||||
require.Equal(t, trs[2].Hash, entries[0].transaction.Hash)
|
||||
require.Equal(t, trs[1].Hash, entries[1].transaction.Hash)
|
||||
}
|
||||
|
||||
func TestGetActivityEntriesFilterByAddresses(t *testing.T) {
|
||||
deps, close := setupTestActivityDB(t)
|
||||
defer close()
|
||||
|
|
|
@ -44,7 +44,8 @@ WITH filter_conditions AS (
|
|||
? AS nowTimestamp,
|
||||
? AS layer2FinalisationDuration,
|
||||
? AS layer1FinalisationDuration,
|
||||
X'0000000000000000000000000000000000000000' AS zeroAddress
|
||||
X'0000000000000000000000000000000000000000' AS zeroAddress,
|
||||
'0x28c427b0611d99da5c4f7368abe57e86b045b483c4689ae93e90745802335b87' as statusMintEvent
|
||||
),
|
||||
-- This UNION between CTE and TEMP TABLE acts as an optimization. As soon as we drop one or use them interchangeably the performance drops significantly.
|
||||
filter_addresses(address) AS (
|
||||
|
@ -250,8 +251,14 @@ WHERE
|
|||
transfers.type = 'erc721'
|
||||
OR (
|
||||
transfers.type = 'erc20'
|
||||
AND method_hash IS NOT NULL
|
||||
AND method_hash IN mint_methods
|
||||
AND (
|
||||
(method_hash IS NOT NULL AND method_hash IN mint_methods)
|
||||
OR (
|
||||
(SELECT 1
|
||||
FROM json_each(transfers.receipt, '$.logs' )
|
||||
WHERE json_extract( value, '$.topics[0]' ) = statusMintEvent) IS NOT NULL
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -275,8 +282,14 @@ WHERE
|
|||
transfers.type = 'erc721'
|
||||
OR (
|
||||
transfers.type = 'erc20'
|
||||
AND method_hash IS NOT NULL
|
||||
AND method_hash IN mint_methods
|
||||
AND (
|
||||
(method_hash IS NOT NULL AND method_hash IN mint_methods)
|
||||
OR (
|
||||
(SELECT 1
|
||||
FROM json_each(transfers.receipt, '$.logs' )
|
||||
WHERE json_extract( value, '$.topics[0]' ) = statusMintEvent) IS NOT NULL
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -255,6 +255,7 @@ type TestTransferOptions struct {
|
|||
TokenID *big.Int
|
||||
NullifyAddresses []eth_common.Address
|
||||
Tx *types.Transaction
|
||||
Receipt *types.Receipt
|
||||
}
|
||||
|
||||
func GenerateTxField(data []byte) *types.Transaction {
|
||||
|
@ -336,6 +337,7 @@ func InsertTestTransferWithOptions(tb testing.TB, db *sql.DB, address eth_common
|
|||
contractAddress: &tr.Contract,
|
||||
tokenID: opt.TokenID,
|
||||
transaction: opt.Tx,
|
||||
receipt: opt.Receipt,
|
||||
}
|
||||
err = updateOrInsertTransfersDBFields(tx, []transferDBFields{transfer})
|
||||
require.NoError(tb, err)
|
||||
|
|
Loading…
Reference in New Issue