diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-04-02 21:13:30 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-04-02 21:13:30 +0800 |
commit | 607fc788e378c62ceea72dbc536da0b484323a44 (patch) | |
tree | 7960e9677c2d27e481d5eadece80769c9a80bfbd /rpc/responses_test.go | |
parent | 1e28b424e7f0f0d16f467ac7bac08b9dc0384106 (diff) | |
parent | b4eef59b6f9631d22fdf62a2b1a40fe05209fccd (diff) | |
download | go-tangerine-607fc788e378c62ceea72dbc536da0b484323a44.tar go-tangerine-607fc788e378c62ceea72dbc536da0b484323a44.tar.gz go-tangerine-607fc788e378c62ceea72dbc536da0b484323a44.tar.bz2 go-tangerine-607fc788e378c62ceea72dbc536da0b484323a44.tar.lz go-tangerine-607fc788e378c62ceea72dbc536da0b484323a44.tar.xz go-tangerine-607fc788e378c62ceea72dbc536da0b484323a44.tar.zst go-tangerine-607fc788e378c62ceea72dbc536da0b484323a44.zip |
Merge pull request #619 from tgerring/rpcfabian
RPC Fabian fixes
Diffstat (limited to 'rpc/responses_test.go')
-rw-r--r-- | rpc/responses_test.go | 111 |
1 files changed, 88 insertions, 23 deletions
diff --git a/rpc/responses_test.go b/rpc/responses_test.go index 43924151a..2ec6d9d15 100644 --- a/rpc/responses_test.go +++ b/rpc/responses_test.go @@ -13,12 +13,16 @@ import ( ) const ( - reHash = `"0x[0-9a-f]{64}"` // 32 bytes - reHashOpt = `"(0x[0-9a-f]{64})"|null` // 32 bytes or null - reAddress = `"0x[0-9a-f]{40}"` // 20 bytes - reAddressOpt = `"0x[0-9a-f]{40}"|null` // 20 bytes or null - reNum = `"0x([1-9a-f][0-9a-f]{1,15})|0"` // must not have left-padded zeros - reData = `"0x[0-9a-f]*"` // can be "empty" + reHash = `"0x[0-9a-f]{64}"` // 32 bytes + reHashOpt = `"(0x[0-9a-f]{64})"|null` // 32 bytes or null + reAddress = `"0x[0-9a-f]{40}"` // 20 bytes + reAddressOpt = `"0x[0-9a-f]{40}"|null` // 20 bytes or null + reNum = `"0x([1-9a-f][0-9a-f]{0,15})|0"` // must not have left-padded zeros + reNumNonZero = `"0x([1-9a-f][0-9a-f]{0,15})"` // non-zero required must not have left-padded zeros + reNumOpt = `"0x([1-9a-f][0-9a-f]{0,15})|0"|null` // must not have left-padded zeros or null + reData = `"0x[0-9a-f]*"` // can be "empty" + // reListHash = `[("\w":"0x[0-9a-f]{64}",?)*]` + // reListObj = `[("\w":(".+"|null),?)*]` ) func TestNewBlockRes(t *testing.T) { @@ -30,26 +34,87 @@ func TestNewBlockRes(t *testing.T) { extra := "" block := types.NewBlock(parentHash, coinbase, root, difficulty, nonce, extra) tests := map[string]string{ - "number": reNum, - "hash": reHash, - "parentHash": reHash, - "nonce": reNum, - "sha3Uncles": reHash, - "logsBloom": reData, - "transactionRoot": reHash, - "stateRoot": reHash, - "miner": reAddress, - "difficulty": `"0x1"`, - "totalDifficulty": reNum, - "size": reNum, - "extraData": reData, - "gasLimit": reNum, + "number": reNum, + "hash": reHash, + "parentHash": reHash, + "nonce": reData, + "sha3Uncles": reHash, + "logsBloom": reData, + "transactionsRoot": reHash, + "stateRoot": reHash, + "miner": reAddress, + "difficulty": `"0x1"`, + "totalDifficulty": reNum, + "size": reNumNonZero, + "extraData": reData, + "gasLimit": reNum, // "minGasPrice": "0x", "gasUsed": reNum, "timestamp": reNum, + // "transactions": reListHash, + // "uncles": reListHash, } + to := common.HexToAddress("0x02") + amount := big.NewInt(1) + gasAmount := big.NewInt(1) + gasPrice := big.NewInt(1) + data := []byte{1, 2, 3} + tx := types.NewTransactionMessage(to, amount, gasAmount, gasPrice, data) + v := NewBlockRes(block, false) + v.Transactions = make([]*TransactionRes, 1) + v.Transactions[0] = NewTransactionRes(tx) + j, _ := json.Marshal(v) + + for k, re := range tests { + match, _ := regexp.MatchString(fmt.Sprintf(`{.*"%s":%s.*}`, k, re), string(j)) + if !match { + t.Error(fmt.Sprintf("%s output json does not match format %s. Got %s", k, re, j)) + } + } +} + +func TestNewBlockResWithTrans(t *testing.T) { + parentHash := common.HexToHash("0x01") + coinbase := common.HexToAddress("0x01") + root := common.HexToHash("0x01") + difficulty := common.Big1 + nonce := uint64(1) + extra := "" + block := types.NewBlock(parentHash, coinbase, root, difficulty, nonce, extra) + tests := map[string]string{ + "number": reNum, + "hash": reHash, + "parentHash": reHash, + "nonce": reData, + "sha3Uncles": reHash, + "logsBloom": reData, + "transactionsRoot": reHash, + "stateRoot": reHash, + "miner": reAddress, + "difficulty": `"0x1"`, + "totalDifficulty": reNum, + "size": reNumNonZero, + "extraData": reData, + "gasLimit": reNum, + // "minGasPrice": "0x", + "gasUsed": reNum, + "timestamp": reNum, + // "transactions": `[{.*}]`, + // "uncles": reListHash, + } + + to := common.HexToAddress("0x02") + amount := big.NewInt(1) + gasAmount := big.NewInt(1) + gasPrice := big.NewInt(1) + data := []byte{1, 2, 3} + tx := types.NewTransactionMessage(to, amount, gasAmount, gasPrice, data) + + v := NewBlockRes(block, true) + v.Transactions = make([]*TransactionRes, 1) + v.Transactions[0] = NewTransactionRes(tx) j, _ := json.Marshal(v) for k, re := range tests { @@ -71,9 +136,9 @@ func TestNewTransactionRes(t *testing.T) { tests := map[string]string{ "hash": reHash, "nonce": reNum, - "blockHash": reHash, - "blockNum": reNum, - "transactionIndex": reNum, + "blockHash": reHashOpt, + "blockNum": reNumOpt, + "transactionIndex": reNumOpt, "from": reAddress, "to": reAddressOpt, "value": reNum, |