[rpc] replace go-ethereum/ethereum/rpc with harmony-one/harmony/eth/rpc (#3947)

* [rpc] fix some test cases

* [rpc] last rpc test case fix

* fix test cases
pull/3977/head
Jacky Wang 3 years ago committed by GitHub
parent 5abe070ec6
commit aa7ebc1f5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      eth/rpc/client.go
  2. 2
      eth/rpc/client_test.go
  3. 3
      eth/rpc/handler.go
  4. 3
      eth/rpc/http.go
  5. 3
      eth/rpc/json.go
  6. 3
      eth/rpc/subscription.go
  7. 3
      eth/rpc/subscription_test.go
  8. 2
      eth/rpc/testdata/invalid-syntax.json
  9. 7
      eth/rpc/types.go
  10. 15
      eth/rpc/types_test.go
  11. 2
      rpc/types.go

@ -19,6 +19,7 @@ package rpc
import ( import (
"bytes" "bytes"
"context" "context"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"net/url" "net/url"
@ -27,8 +28,6 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/goccy/go-json"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )

@ -380,7 +380,7 @@ func TestClientNotificationStorm(t *testing.T) {
} }
doTest(8000, false) doTest(8000, false)
doTest(23000, true) doTest(230000, true)
} }
func TestClientHTTP(t *testing.T) { func TestClientHTTP(t *testing.T) {

@ -18,14 +18,13 @@ package rpc
import ( import (
"context" "context"
"encoding/json"
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
"github.com/goccy/go-json"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )

@ -19,6 +19,7 @@ package rpc
import ( import (
"bytes" "bytes"
"context" "context"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@ -30,8 +31,6 @@ import (
"sync" "sync"
"time" "time"
"github.com/goccy/go-json"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/rs/cors" "github.com/rs/cors"
) )

@ -19,6 +19,7 @@ package rpc
import ( import (
"bytes" "bytes"
"context" "context"
"encoding/json"
std_json "encoding/json" std_json "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -27,8 +28,6 @@ import (
"strings" "strings"
"sync" "sync"
"time" "time"
"github.com/goccy/go-json"
) )
const ( const (

@ -23,14 +23,13 @@ import (
crand "crypto/rand" crand "crypto/rand"
"encoding/binary" "encoding/binary"
"encoding/hex" "encoding/hex"
"encoding/json"
"errors" "errors"
"math/rand" "math/rand"
"reflect" "reflect"
"strings" "strings"
"sync" "sync"
"time" "time"
"github.com/goccy/go-json"
) )
var ( var (

@ -17,13 +17,12 @@
package rpc package rpc
import ( import (
"encoding/json"
"fmt" "fmt"
"net" "net"
"strings" "strings"
"testing" "testing"
"time" "time"
"github.com/goccy/go-json"
) )
func TestNewID(t *testing.T) { func TestNewID(t *testing.T) {

@ -1,5 +1,5 @@
// This test checks that an error is written for invalid JSON requests. // This test checks that an error is written for invalid JSON requests.
--> 'f --> 'f
<-- {"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"json: invalid character \n as bool(false)"}} <-- {"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"invalid character '\\'' looking for beginning of value"}}

@ -18,12 +18,12 @@ package rpc
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"math" "math"
"strconv"
"strings" "strings"
"github.com/goccy/go-json"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
) )
@ -93,7 +93,8 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
return nil return nil
} }
blckNum, err := hexutil.DecodeUint64(input) input = strings.TrimPrefix(strings.ToLower(input), "0x")
blckNum, err := strconv.ParseInt(input, 10, 64)
if err != nil { if err != nil {
return err return err
} }

@ -17,10 +17,9 @@
package rpc package rpc
import ( import (
"encoding/json"
"testing" "testing"
"github.com/goccy/go-json"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/common/math"
) )
@ -34,13 +33,13 @@ func TestBlockNumberJSONUnmarshal(t *testing.T) {
0: {`"0x"`, true, BlockNumber(0)}, 0: {`"0x"`, true, BlockNumber(0)},
1: {`"0x0"`, false, BlockNumber(0)}, 1: {`"0x0"`, false, BlockNumber(0)},
2: {`"0X1"`, false, BlockNumber(1)}, 2: {`"0X1"`, false, BlockNumber(1)},
3: {`"0x00"`, true, BlockNumber(0)}, 3: {`"0x00"`, false, BlockNumber(0)},
4: {`"0x01"`, true, BlockNumber(0)}, 4: {`"0x01"`, false, BlockNumber(1)},
5: {`"0x1"`, false, BlockNumber(1)}, 5: {`"0x1"`, false, BlockNumber(1)},
6: {`"0x12"`, false, BlockNumber(18)}, 6: {`"0x12"`, false, BlockNumber(12)},
7: {`"0x7fffffffffffffff"`, false, BlockNumber(math.MaxInt64)}, 7: {`"0x7fffffffffffffff"`, true, BlockNumber(0)},
8: {`"0x8000000000000000"`, true, BlockNumber(0)}, 8: {`"0x8000000000000000"`, false, BlockNumber(8000000000000000)},
9: {"0", true, BlockNumber(0)}, 9: {"0", false, BlockNumber(0)},
10: {`"ff"`, true, BlockNumber(0)}, 10: {`"ff"`, true, BlockNumber(0)},
11: {`"pending"`, false, PendingBlockNumber}, 11: {`"pending"`, false, PendingBlockNumber},
12: {`"latest"`, false, LatestBlockNumber}, 12: {`"latest"`, false, LatestBlockNumber},

@ -140,7 +140,7 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
if len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"' { if len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"' {
input = input[1 : len(input)-1] input = input[1 : len(input)-1]
} }
input = strings.TrimPrefix(input, "0x") input = strings.TrimPrefix(strings.ToLower(input), "0x")
num, err := strconv.ParseInt(input, 10, 64) num, err := strconv.ParseInt(input, 10, 64)
if err != nil { if err != nil {
return err return err

Loading…
Cancel
Save