[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 (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net/url"
@ -27,8 +28,6 @@ import (
"sync/atomic"
"time"
"github.com/goccy/go-json"
"github.com/ethereum/go-ethereum/log"
)

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

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

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

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

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

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

@ -1,5 +1,5 @@
// This test checks that an error is written for invalid JSON requests.
--> '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 (
"context"
"encoding/json"
"fmt"
"math"
"strconv"
"strings"
"github.com/goccy/go-json"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
)
@ -93,7 +93,8 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
return nil
}
blckNum, err := hexutil.DecodeUint64(input)
input = strings.TrimPrefix(strings.ToLower(input), "0x")
blckNum, err := strconv.ParseInt(input, 10, 64)
if err != nil {
return err
}

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

Loading…
Cancel
Save