Skip to content

Commit

Permalink
Add GetTransactionReceipt method
Browse files Browse the repository at this point in the history
  • Loading branch information
chenfengjin committed Aug 19, 2021
1 parent 1ac42ab commit 7a59254
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 20 deletions.
14 changes: 14 additions & 0 deletions kernel/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func NewEVMProxy(manager contract.Manager) (EVMProxy, error) {
// SendTransaction is not used currently
// registry.RegisterKernMethod("$evm", "SendTransaction", p.sendTransaction)
registry.RegisterKernMethod("$evm", "SendRawTransaction", p.sendRawTransaction)
registry.RegisterKernMethod("$evm", "GetTransactionReceipt", p.getTransactionReceipt)

// registry.RegisterKernMethod("$evm", "ContractCall", p.ContractCall)
return &p, nil
}
Expand Down Expand Up @@ -224,3 +226,15 @@ func (p *proxy) verifySignature(
}
return nil
}
func (p *proxy) getTransactionReceipt(ctx contract.KContext) (*contract.Response, error) {
args := ctx.Args()
txHash := args["tx_hash"]
tx, err := ctx.Get(ETH_TX_PREFIX, txHash)
if err != nil {
return nil, err
}
return &contract.Response{
Status: 200,
Body: tx,
}, nil
}
57 changes: 37 additions & 20 deletions kernel/evm/evm_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package evm

import (
"bytes"
"math/big"

_ "github.com/xuperchain/xupercore/bcs/contract/evm"
_ "github.com/xuperchain/xupercore/bcs/contract/native"
_ "github.com/xuperchain/xupercore/bcs/contract/xvm"
"github.com/xuperchain/xupercore/kernel/contract/sandbox"
"github.com/xuperchain/xupercore/protos"
"math/big"

"encoding/hex"
"io/ioutil"
"testing"

"github.com/xuperchain/xupercore/kernel/contract"
_ "github.com/xuperchain/xupercore/kernel/contract"
_ "github.com/xuperchain/xupercore/kernel/contract/kernel"
_ "github.com/xuperchain/xupercore/kernel/contract/manager"
"github.com/xuperchain/xupercore/kernel/contract/mock"
"io/ioutil"
"testing"
)

func TestEVMProxy(t *testing.T) {
Expand Down Expand Up @@ -66,6 +69,7 @@ func TestEVMProxy(t *testing.T) {
if err != nil {
t.Fatal(err)
}
signedTx := []byte("0xf867808082520894f97798df751deb4b6e39d4cf998ee7cd4dcb9acc880de0b6b3a76400008025a0f0d2396973296cd6a71141c974d4a851f5eae8f08a8fba2dc36a0fef9bd6440ca0171995aa750d3f9f8e4d0eac93ff67634274f3c5acf422723f49ff09a6885422")
t.Run("SendRawTransaction", func(t *testing.T) {
th.SetUtxoReader(sandbox.NewUTXOReaderFromInput([]*protos.TxInput{
{
Expand All @@ -75,39 +79,52 @@ func TestEVMProxy(t *testing.T) {
}))

resp, err = th.Invoke("xkernel", "$evm", "SendRawTransaction", map[string][]byte{
"signed_tx": []byte("0xf867808082520894f97798df751deb4b6e39d4cf998ee7cd4dcb9acc880de0b6b3a76400008025a0f0d2396973296cd6a71141c974d4a851f5eae8f08a8fba2dc36a0fef9bd6440ca0171995aa750d3f9f8e4d0eac93ff67634274f3c5acf422723f49ff09a6885422"),
"signed_tx": signedTx,
"tx_hash": []byte("tx_hash"),
})
if err != nil {
t.Error(err)
return
}
})

t.Run("ContractCall", func(t *testing.T) {
resp, err = th.Invoke("xkernel", "$evm", "ContractCall", map[string][]byte{
"to": []byte("313131312D2D2D2D2D2D2D2D2D636F756E746572"),
"from": []byte("b60e8dd61c5d32be8058bb8eb970870f07233155"),
"input": []byte("ae896c870000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000678636861696e0000000000000000000000000000000000000000000000000000"),
t.Run("GetTransactionReceipt", func(t *testing.T) {
resp, err := th.Invoke("xkernel", "$evm", "GetTransactionReceipt", map[string][]byte{
"tx_hash": []byte("tx_hash"),
})
if err != nil {
t.Error(err)
return
}
resp, err = th.Invoke("evm", "counter", "get", map[string][]byte{
"input": []byte(`{"key":"xchain"}`),
"jsonEncoded": []byte("true"),
})
if err != nil {
if !bytes.Equal(resp.Body, signedTx) {
t.Error(err)
return
}
if string(resp.Body) != `[{"0":"1"}]` {
t.Errorf("expect %s,get:%s", `[{"0":"1"}]`, string(resp.Body))
return
}

})

// t.Run("ContractCall", func(t *testing.T) {
// resp, err = th.Invoke("xkernel", "$evm", "ContractCall", map[string][]byte{
// "to": []byte("313131312D2D2D2D2D2D2D2D2D636F756E746572"),
// "from": []byte("b60e8dd61c5d32be8058bb8eb970870f07233155"),
// "input": []byte("ae896c870000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000678636861696e0000000000000000000000000000000000000000000000000000"),
// })
// if err != nil {
// t.Error(err)
// return
// }
// resp, err = th.Invoke("evm", "counter", "get", map[string][]byte{
// "input": []byte(`{"key":"xchain"}`),
// "jsonEncoded": []byte("true"),
// })
// if err != nil {
// t.Error(err)
// return
// }
// if string(resp.Body) != `[{"0":"1"}]` {
// t.Errorf("expect %s,get:%s", `[{"0":"1"}]`, string(resp.Body))
// return
// }
//
// })
_ = resp
}

Expand Down

0 comments on commit 7a59254

Please sign in to comment.