Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move token id from Data to Topic in ERC721 Event #1837

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions app/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,64 +182,68 @@
var topics []common.Hash
switch action {
case "transfer_nft", "send_nft", "burn":
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
return nil, false
}

Check warning on line 188 in app/receipt.go

View check run for this annotation

Codecov / codecov/patch

app/receipt.go#L187-L188

Added lines #L187 - L188 were not covered by tests
topics = []common.Hash{
ERC721TransferTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
app.GetEvmAddressAttribute(ctx, wasmEvent, "recipient"),
}
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
return nil, false
common.BigToHash(tokenID),
}
return &ethtypes.Log{
Address: pointerAddr,
Topics: topics,
Data: common.BigToHash(tokenID).Bytes(),
Data: EmptyHash.Bytes(),
}, true
case "mint":
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
return nil, false
}

Check warning on line 204 in app/receipt.go

View check run for this annotation

Codecov / codecov/patch

app/receipt.go#L203-L204

Added lines #L203 - L204 were not covered by tests
topics = []common.Hash{
ERC721TransferTopic,
EmptyHash,
app.GetEvmAddressAttribute(ctx, wasmEvent, "owner"),
}
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
return nil, false
common.BigToHash(tokenID),
}
return &ethtypes.Log{
Address: pointerAddr,
Topics: topics,
Data: common.BigToHash(tokenID).Bytes(),
Data: EmptyHash.Bytes(),
}, true
case "approve":
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
return nil, false
}

Check warning on line 220 in app/receipt.go

View check run for this annotation

Codecov / codecov/patch

app/receipt.go#L219-L220

Added lines #L219 - L220 were not covered by tests
topics = []common.Hash{
ERC721ApprovalTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
app.GetEvmAddressAttribute(ctx, wasmEvent, "spender"),
}
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
return nil, false
common.BigToHash(tokenID),
}
return &ethtypes.Log{
Address: pointerAddr,
Topics: topics,
Data: common.BigToHash(tokenID).Bytes(),
Data: EmptyHash.Bytes(),
}, true
case "revoke":
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
return nil, false
}

Check warning on line 236 in app/receipt.go

View check run for this annotation

Codecov / codecov/patch

app/receipt.go#L235-L236

Added lines #L235 - L236 were not covered by tests
topics = []common.Hash{
ERC721ApprovalTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
EmptyHash,
}
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
return nil, false
common.BigToHash(tokenID),
}
return &ethtypes.Log{
Address: pointerAddr,
Topics: topics,
Data: common.BigToHash(tokenID).Bytes(),
Data: EmptyHash.Bytes(),
}, true
case "approve_all":
topics = []common.Hash{
Expand Down
13 changes: 9 additions & 4 deletions app/receipt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ func TestEvmEventsForCw20(t *testing.T) {
require.Equal(t, uint32(0), res.Code)
receipt, err = testkeeper.EVMTestApp.EvmKeeper.GetTransientReceipt(ctx, signedTx.Hash())
require.Nil(t, err)
fmt.Println(receipt.Logs)
require.Equal(t, 1, len(receipt.Logs))
require.NotEmpty(t, receipt.LogsBloom)
require.Equal(t, mockPointerAddr.Hex(), receipt.Logs[0].Address)
Expand Down Expand Up @@ -261,9 +260,11 @@ func TestEvmEventsForCw721(t *testing.T) {
require.NotEmpty(t, receipt.LogsBloom)
require.Equal(t, mockPointerAddr.Hex(), receipt.Logs[0].Address)
require.Equal(t, uint32(0), receipt.Logs[0].Index)
tokenIdHash := receipt.Logs[0].Topics[3]
require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000002", tokenIdHash)
_, found = testkeeper.EVMTestApp.EvmKeeper.GetEVMTxDeferredInfo(ctx)
require.True(t, found)
require.Equal(t, common.HexToHash("0x2").Bytes(), receipt.Logs[0].Data)
require.Equal(t, common.HexToHash("0x0").Bytes(), receipt.Logs[0].Data)

// revoke
payload = []byte(fmt.Sprintf("{\"revoke\":{\"spender\":\"%s\",\"token_id\":\"2\"}}", recipient.String()))
Expand All @@ -289,7 +290,9 @@ func TestEvmEventsForCw721(t *testing.T) {
require.Equal(t, mockPointerAddr.Hex(), receipt.Logs[0].Address)
_, found = testkeeper.EVMTestApp.EvmKeeper.GetEVMTxDeferredInfo(ctx)
require.True(t, found)
require.Equal(t, common.HexToHash("0x2").Bytes(), receipt.Logs[0].Data)
tokenIdHash = receipt.Logs[0].Topics[3]
require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000002", tokenIdHash)
require.Equal(t, common.HexToHash("0x0").Bytes(), receipt.Logs[0].Data)

// approve all
payload = []byte(fmt.Sprintf("{\"approve_all\":{\"operator\":\"%s\"}}", recipient.String()))
Expand Down Expand Up @@ -367,7 +370,9 @@ func TestEvmEventsForCw721(t *testing.T) {
require.Equal(t, mockPointerAddr.Hex(), receipt.Logs[0].Address)
_, found = testkeeper.EVMTestApp.EvmKeeper.GetEVMTxDeferredInfo(ctx)
require.True(t, found)
require.Equal(t, common.HexToHash("0x2").Bytes(), receipt.Logs[0].Data)
tokenIdHash = receipt.Logs[0].Topics[3]
require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000002", tokenIdHash)
require.Equal(t, common.HexToHash("0x0").Bytes(), receipt.Logs[0].Data)
}

func signTx(txBuilder client.TxBuilder, privKey cryptotypes.PrivKey, acc authtypes.AccountI) sdk.Tx {
Expand Down
Loading