Extended testGetDefaultConfig to support Rinkeby (#241)

This pull requests only extends testGetDefaultConfig to run against Rinkeby as well and fixes TestJailWhisper.
This commit is contained in:
Ivan Tomilov 2017-09-08 15:32:02 +03:00 committed by GitHub
parent 6a096607cf
commit c85525e139
6 changed files with 187 additions and 256 deletions

View File

@ -17,6 +17,7 @@ import (
"github.com/ethereum/go-ethereum/core"
gethparams "github.com/ethereum/go-ethereum/params"
"fmt"
"github.com/status-im/status-go/geth/common"
"github.com/status-im/status-go/geth/node"
"github.com/status-im/status-go/geth/params"
@ -39,6 +40,9 @@ var nodeConfigJSON = `{
func testExportedAPI(t *testing.T, done chan struct{}) {
<-startTestNode(t)
// FIXME(tiabc): All of that is done because usage of cgo is not supported in tests.
// Probably, there should be a cleaner way, for example, test cgo bindings in e2e tests
// separately from other internal tests.
tests := []struct {
name string
fn func(t *testing.T) bool
@ -163,103 +167,34 @@ func testVerifyAccountPassword(t *testing.T) bool {
}
func testGetDefaultConfig(t *testing.T) bool {
// test Mainnet config
nodeConfig := params.NodeConfig{}
networks := []struct {
chainID int
refChainConfig *gethparams.ChainConfig
}{
{params.MainNetworkID, gethparams.MainnetChainConfig},
{params.RopstenNetworkID, gethparams.TestnetChainConfig},
{params.RinkebyNetworkID, gethparams.RinkebyChainConfig},
}
for i := range networks {
network := networks[i]
rawResponse := GenerateConfig(C.CString("/tmp/data-folder"), 1, 1)
t.Run(fmt.Sprintf("networkID=%d", network.chainID), func(t *testing.T) {
var (
nodeConfig = params.NodeConfig{}
rawResponse = GenerateConfig(C.CString("/tmp/data-folder"), C.int(network.chainID), 1)
)
if err := json.Unmarshal([]byte(C.GoString(rawResponse)), &nodeConfig); err != nil {
t.Errorf("cannot decode response (%s): %v", C.GoString(rawResponse), err)
return false
}
genesis := new(core.Genesis)
if err := json.Unmarshal([]byte(nodeConfig.LightEthConfig.Genesis), genesis); err != nil {
t.Error(err)
return false
}
chainConfig := genesis.Config
if chainConfig.HomesteadBlock.Cmp(gethparams.MainnetChainConfig.HomesteadBlock) != 0 {
t.Error("invalid chainConfig.HomesteadBlock")
return false
}
if chainConfig.DAOForkBlock.Cmp(gethparams.MainnetChainConfig.DAOForkBlock) != 0 {
t.Error("invalid chainConfig.DAOForkBlock")
return false
}
if chainConfig.DAOForkSupport != true {
t.Error("invalid chainConfig.DAOForkSupport")
return false
}
if chainConfig.EIP150Block.Cmp(gethparams.MainnetChainConfig.EIP150Block) != 0 {
t.Error("invalid chainConfig.EIP150Block")
return false
}
if chainConfig.EIP150Hash != gethparams.MainnetChainConfig.EIP150Hash {
t.Error("invalid chainConfig.EIP150Hash")
return false
}
if chainConfig.EIP155Block.Cmp(gethparams.MainnetChainConfig.EIP155Block) != 0 {
t.Error("invalid chainConfig.EIP155Block")
return false
}
if chainConfig.EIP158Block.Cmp(gethparams.MainnetChainConfig.EIP158Block) != 0 {
t.Error("invalid chainConfig.EIP158Block")
return false
}
if chainConfig.ChainId.Cmp(gethparams.MainnetChainConfig.ChainId) != 0 {
t.Error("invalid chainConfig.ChainId")
return false
}
// test Testnet
nodeConfig = params.NodeConfig{}
rawResponse = GenerateConfig(C.CString("/tmp/data-folder"), 3, 1)
if err := json.Unmarshal([]byte(C.GoString(rawResponse)), &nodeConfig); err != nil {
t.Errorf("cannot decode response (%s): %v", C.GoString(rawResponse), err)
return false
require.Equal(t, network.refChainConfig, genesis.Config)
})
}
genesis = new(core.Genesis)
if err := json.Unmarshal([]byte(nodeConfig.LightEthConfig.Genesis), genesis); err != nil {
t.Error(err)
return false
}
chainConfig = genesis.Config
refChainConfig := gethparams.TestnetChainConfig
if chainConfig.HomesteadBlock.Cmp(refChainConfig.HomesteadBlock) != 0 {
t.Error("invalid chainConfig.HomesteadBlock")
return false
}
if chainConfig.DAOForkBlock != nil { // already forked
t.Error("invalid chainConfig.DAOForkBlock")
return false
}
if chainConfig.DAOForkSupport != refChainConfig.DAOForkSupport {
t.Error("invalid chainConfig.DAOForkSupport")
return false
}
if chainConfig.EIP150Block.Cmp(refChainConfig.EIP150Block) != 0 {
t.Error("invalid chainConfig.EIP150Block")
return false
}
if chainConfig.EIP150Hash != refChainConfig.EIP150Hash {
t.Error("invalid chainConfig.EIP150Hash")
return false
}
if chainConfig.EIP155Block.Cmp(refChainConfig.EIP155Block) != 0 {
t.Error("invalid chainConfig.EIP155Block")
return false
}
if chainConfig.EIP158Block.Cmp(refChainConfig.EIP158Block) != 0 {
t.Error("invalid chainConfig.EIP158Block")
return false
}
if chainConfig.ChainId.Cmp(refChainConfig.ChainId) != 0 {
t.Error("invalid chainConfig.ChainId")
return false
}
return true
}

View File

@ -22,15 +22,18 @@ import (
const (
whisperMessage1 = `test message 1 (K1 -> K2, signed+encrypted, from us)`
whisperMessage2 = `test message 2 (K1 -> K1, signed+encrypted to ourselves)`
whisperMessage3 = `test message 3 (K1 -> "", signed broadcast)`
whisperMessage4 = `test message 4 ("" -> "", anon broadcast)`
whisperMessage5 = `test message 5 ("" -> K1, encrypted anon broadcast)`
whisperMessage6 = `test message 6 (K2 -> K1, signed+encrypted, to us)`
whisperMessage2 = `test message 3 (K1 -> "", signed broadcast)`
whisperMessage3 = `test message 4 ("" -> "", anon broadcast)`
whisperMessage4 = `test message 5 ("" -> K1, encrypted anon broadcast)`
whisperMessage5 = `test message 6 (K2 -> K1, signed+encrypted, to us)`
txSendFolder = "testdata/jail/tx-send/"
testChatID = "testChat"
)
var (
baseStatusJSCode = string(static.MustAsset("testdata/jail/status.js"))
)
func (s *BackendTestSuite) TestJailSendQueuedTransaction() {
require := s.Require()
@ -276,6 +279,8 @@ func (s *BackendTestSuite) TestJailWhisper() {
jailInstance := s.backend.JailManager()
require.NotNil(jailInstance)
jailInstance.BaseJS(baseStatusJSCode)
whisperService := s.WhisperService()
whisperAPI := whisper.NewPublicWhisperAPI(whisperService)
@ -311,7 +316,6 @@ func (s *BackendTestSuite) TestJailWhisper() {
whisperMessage3: false,
whisperMessage4: false,
whisperMessage5: false,
whisperMessage6: false,
}
installedFilters := map[string]string{
whisperMessage1: "",
@ -319,7 +323,6 @@ func (s *BackendTestSuite) TestJailWhisper() {
whisperMessage3: "",
whisperMessage4: "",
whisperMessage5: "",
whisperMessage6: "",
}
testCases := []struct {
@ -330,7 +333,7 @@ func (s *BackendTestSuite) TestJailWhisper() {
{
"test 0: ensure correct version of Whisper is used",
`
var expectedVersion = '0x5';
var expectedVersion = '5.0';
if (web3.version.whisper != expectedVersion) {
throw 'unexpected shh version, expected: ' + expectedVersion + ', got: ' + web3.version.whisper;
}
@ -341,41 +344,42 @@ func (s *BackendTestSuite) TestJailWhisper() {
"test 1: encrypted signed message from us (From != nil && To != nil)",
`
var identity1 = '` + accountKey1Hex + `';
if (!web3.shh.hasKeyPair(identity1)) {
if (!shh.hasKeyPair(identity1)) {
throw 'idenitity "` + accountKey1Hex + `" not found in whisper';
}
var identity2 = '` + accountKey2Hex + `';
if (!web3.shh.hasKeyPair(identity2)) {
throw 'idenitity "` + accountKey2Hex + `" not found in whisper';
if (!shh.hasKeyPair(identity2)) {
throw 'identitity "` + accountKey2Hex + `" not found in whisper';
}
var topic = makeTopic();
var payload = '` + whisperMessage1 + `';
// start watching for messages
var filter = shh.filter({
type: "asym",
var filter = shh.newMessageFilter({
sig: identity1,
key: identity2,
privateKeyID: identity2,
topics: [topic]
});
console.log(JSON.stringify(filter));
// post message
var message = {
type: "asym",
sig: identity1,
key: identity2,
topic: topic,
payload: payload,
ttl: 20,
powTarget: 0.01,
powTime: 20,
topic: topic,
sig: identity1,
pubKey: identity2,
payload: web3.toHex(payload),
};
var err = shh.post(message)
if (err !== null) {
throw 'message not sent: ' + message;
var sent = shh.post(message)
if (!sent) {
throw 'message not sent: ' + JSON.stringify(message);
}
var filterName = '` + whisperMessage1 + `';
var filterId = filter.filterId;
if (!filterId) {
@ -385,36 +389,43 @@ func (s *BackendTestSuite) TestJailWhisper() {
true,
},
{
"test 2: encrypted signed message to yourself (From != nil && To != nil)",
"test 2: signed (known sender) broadcast (From != nil && To == nil)",
`
var identity = '` + accountKey1Hex + `';
if (!web3.shh.hasKeyPair(identity)) {
if (!shh.hasKeyPair(identity)) {
throw 'idenitity "` + accountKey1Hex + `" not found in whisper';
}
var topic = makeTopic();
var payload = '` + whisperMessage2 + `';
// generate symmetric key
var keyid = shh.newSymKey();
if (!shh.hasSymKey(keyid)) {
throw new Error('key not found');
}
// start watching for messages
var filter = shh.filter({
type: "asym",
var filter = shh.newMessageFilter({
sig: identity,
key: identity,
topics: [topic],
symKeyID: keyid
});
// post message
var message = {
type: "asym",
sig: identity,
key: identity,
topic: topic,
payload: payload,
ttl: 20,
powTarget: 0.01,
powTime: 20,
topic: topic,
sig: identity,
symKeyID: keyid,
payload: web3.toHex(payload),
};
var err = shh.post(message)
if (err !== null) {
throw 'message not sent: ' + message;
var sent = shh.post(message)
if (!sent) {
throw 'message not sent: ' + JSON.stringify(message);
}
var filterName = '` + whisperMessage2 + `';
@ -426,42 +437,36 @@ func (s *BackendTestSuite) TestJailWhisper() {
true,
},
{
"test 3: signed (known sender) broadcast (From != nil && To == nil)",
"test 3: anonymous broadcast (From == nil && To == nil)",
`
var identity = '` + accountKey1Hex + `';
if (!web3.shh.hasKeyPair(identity)) {
throw 'idenitity "` + accountKey1Hex + `" not found in whisper';
}
var topic = makeTopic();
var payload = '` + whisperMessage3 + `';
// generate symmetric key
var keyid = shh.generateSymmetricKey();
if (!shh.hasSymmetricKey(keyid)) {
var keyid = shh.newSymKey();
if (!shh.hasSymKey(keyid)) {
throw new Error('key not found');
}
// start watching for messages
var filter = shh.filter({
type: "sym",
sig: identity,
var filter = shh.newMessageFilter({
topics: [topic],
key: keyid
symKeyID: keyid
});
// post message
var message = {
type: "sym",
sig: identity,
topic: topic,
payload: payload,
ttl: 20,
key: keyid
powTarget: 0.01,
powTime: 20,
topic: topic,
symKeyID: keyid,
payload: web3.toHex(payload),
};
var err = shh.post(message)
if (err !== null) {
throw 'message not sent: ' + message;
var sent = shh.post(message)
if (!sent) {
throw 'message not sent: ' + JSON.stringify(message);
}
var filterName = '` + whisperMessage3 + `';
@ -473,35 +478,35 @@ func (s *BackendTestSuite) TestJailWhisper() {
true,
},
{
"test 4: anonymous broadcast (From == nil && To == nil)",
"test 4: encrypted anonymous message (From == nil && To != nil)",
`
var identity = '` + accountKey2Hex + `';
if (!shh.hasKeyPair(identity)) {
throw 'idenitity "` + accountKey2Hex + `" not found in whisper';
}
var topic = makeTopic();
var payload = '` + whisperMessage4 + `';
// generate symmetric key
var keyid = shh.generateSymmetricKey();
if (!shh.hasSymmetricKey(keyid)) {
throw new Error('key not found');
}
// start watching for messages
var filter = shh.filter({
type: "sym",
var filter = shh.newMessageFilter({
privateKeyID: identity,
topics: [topic],
key: keyid
});
// post message
var message = {
type: "sym",
topic: topic,
payload: payload,
ttl: 20,
key: keyid
powTarget: 0.01,
powTime: 20,
topic: topic,
pubKey: identity,
payload: web3.toHex(payload),
};
var err = shh.post(message)
if (err !== null) {
throw 'message not sent: ' + err;
var sent = shh.post(message)
if (!sent) {
throw 'message not sent: ' + JSON.stringify(message);
}
var filterName = '` + whisperMessage4 + `';
@ -513,36 +518,39 @@ func (s *BackendTestSuite) TestJailWhisper() {
true,
},
{
"test 5: encrypted anonymous message (From == nil && To != nil)",
"test 5: encrypted signed response to us (From != nil && To != nil)",
`
var identity = '` + accountKey2Hex + `';
if (!web3.shh.hasKeyPair(identity)) {
var identity1 = '` + accountKey1Hex + `';
if (!shh.hasKeyPair(identity1)) {
throw 'idenitity "` + accountKey1Hex + `" not found in whisper';
}
var identity2 = '` + accountKey2Hex + `';
if (!shh.hasKeyPair(identity2)) {
throw 'idenitity "` + accountKey2Hex + `" not found in whisper';
}
var topic = makeTopic();
var payload = '` + whisperMessage5 + `';
// start watching for messages
var filter = shh.filter({
type: "asym",
key: identity,
var filter = shh.newMessageFilter({
privateKeyID: identity1,
sig: identity2,
topics: [topic],
});
// post message
var message = {
type: "asym",
key: identity,
sig: identity2,
pubKey: identity1,
topic: topic,
payload: payload,
ttl: 20
payload: web3.toHex(payload),
ttl: 20,
powTime: 20,
powTarget: 0.01,
};
var err = shh.post(message)
if (err !== null) {
var sent = shh.post(message)
if (!sent) {
throw 'message not sent: ' + message;
}
var filterName = '` + whisperMessage5 + `';
var filterId = filter.filterId;
if (!filterId) {
@ -551,57 +559,12 @@ func (s *BackendTestSuite) TestJailWhisper() {
`,
true,
},
{
"test 6: encrypted signed response to us (From != nil && To != nil)",
`
var identity1 = '` + accountKey1Hex + `';
if (!web3.shh.hasKeyPair(identity1)) {
throw 'idenitity "` + accountKey1Hex + `" not found in whisper';
}
var identity2 = '` + accountKey2Hex + `';
if (!web3.shh.hasKeyPair(identity2)) {
throw 'idenitity "` + accountKey2Hex + `" not found in whisper';
}
var topic = makeTopic();
var payload = '` + whisperMessage6 + `';
// start watching for messages
var filter = shh.filter({
type: "asym",
sig: identity2,
key: identity1,
topics: [topic]
});
// post message
var message = {
type: "asym",
sig: identity2,
key: identity1,
topic: topic,
payload: payload,
ttl: 20
};
var err = shh.post(message)
if (err !== null) {
throw 'message not sent: ' + message;
}
var filterName = '` + whisperMessage6 + `';
var filterId = filter.filterId;
if (!filterId) {
throw 'filter not installed properly';
}
`,
true,
},
}
for _, testCase := range testCases {
s.T().Log(testCase.name)
testCaseKey := crypto.Keccak256Hash([]byte(testCase.name)).Hex()
jailInstance.Parse(testCaseKey, `
var shh = web3.shh;
var makeTopic = function () {
@ -718,7 +681,8 @@ func (s *BackendTestSuite) TestJailVMPersistence() {
}
jailInstance := s.backend.JailManager()
jailInstance.BaseJS(string(static.MustAsset("testdata/jail/status.js")))
jailInstance.BaseJS(baseStatusJSCode)
parseResult := jailInstance.Parse(testChatID, `
var total = 0;
_status_catalog['ping'] = function(params) {

View File

@ -620,7 +620,7 @@ func (s *BackendTestSuite) TestEvictionOfQueuedTransactions() {
for i := 0; i < 10; i++ {
go s.backend.SendTransaction(nil, common.SendTxArgs{}) // nolint: errcheck
}
time.Sleep(1 * time.Second)
time.Sleep(2 * time.Second) // FIXME(tiabc): more reliable synchronization to ensure all transactions are enqueued
log.Info(fmt.Sprintf("Number of transactions queued: %d. Queue size (shouldn't be more than %d): %d",
i, node.DefaultTxQueueCap, txQueue.Count()))

View File

@ -1,3 +1,4 @@
// Package testing implements the base level testing types needed.
package testing
import (
@ -6,6 +7,7 @@ import (
"io"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
@ -136,13 +138,20 @@ func FirstBlockHash(require *assertions.Assertions, nodeManager common.NodeManag
// MakeTestNodeConfig defines a function to return a giving params.NodeConfig
// where specific network addresses are assigned based on provieded network id.
func MakeTestNodeConfig(networkID int) (*params.NodeConfig, error) {
testDir := filepath.Join(TestDataDir, TestNetworkNames[networkID])
if runtime.GOOS == "windows" {
testDir = filepath.ToSlash(testDir)
}
configJSON := `{
"NetworkId": ` + strconv.Itoa(networkID) + `,
"DataDir": "` + filepath.Join(TestDataDir, TestNetworkNames[networkID]) + `",
"DataDir": "` + testDir + `",
"HTTPPort": ` + strconv.Itoa(TestConfig.Node.HTTPPort) + `,
"WSPort": ` + strconv.Itoa(TestConfig.Node.WSPort) + `,
"LogLevel": "INFO"
}`
nodeConfig, err := params.LoadNodeConfig(configJSON)
if err != nil {
return nil, err

View File

@ -1,26 +1,26 @@
{
"name": "status-go",
"version": "0.9.6",
"name": "status-js",
"version": "0.9.8",
"description": "JavaScript tests for RPC API (Whisper/5, Swarm)",
"main": "index.js",
"dependencies": {},
"devDependencies": {
"chai": "^3.5.0",
"mocha": "^3.3.0",
"requirejs": "^2.3.3",
"web3": "github:farazdagi/web3.js#geth/1.6.1-unstable"
"mocha": "^3.5.0",
"requirejs": "^2.3.4",
"web3": "https://github.com/status-im/web3.js#status-develop"
},
"scripts": {
"test": "mocha --bail --slow 1000 --full-trace static/tests"
},
"repository": {
"type": "git",
"url": "git+https://github.com/farazdagi/status-go.git"
"url": "git+https://github.com/status-im/status-go.git"
},
"author": "Victor Farazdagi",
"license": "ISC",
"bugs": {
"url": "https://github.com/farazdagi/status-go/issues"
"url": "https://github.com/status-im/status-go/issues"
},
"homepage": "https://github.com/farazdagi/status-go#readme"
"homepage": "https://github.com/status-im/status-go#readme"
}

File diff suppressed because one or more lines are too long