TestTransactionJSON tests serializing/de-serializing to/from JSON.
(t *testing.T)
| 179 | |
| 180 | // TestTransactionJSON tests serializing/de-serializing to/from JSON. |
| 181 | func TestTransactionJSON(t *testing.T) { |
| 182 | key, err := crypto.GenerateKey() |
| 183 | if err != nil { |
| 184 | t.Fatalf("could not generate key: %v", err) |
| 185 | } |
| 186 | signer := NewCep1Signer(common.Big1) |
| 187 | |
| 188 | for i := uint64(0); i < 25; i++ { |
| 189 | var tx *Transaction |
| 190 | switch i % 2 { |
| 191 | case 0: |
| 192 | tx = NewTransaction(i, common.Address{1}, common.Big0, 1, common.Big2, []byte("abcdef")) |
| 193 | case 1: |
| 194 | tx = NewContractCreation(i, common.Big0, 1, common.Big2, []byte("abcdef")) |
| 195 | } |
| 196 | |
| 197 | tx, err := SignTx(tx, signer, key) |
| 198 | if err != nil { |
| 199 | t.Fatalf("could not sign transaction: %v", err) |
| 200 | } |
| 201 | |
| 202 | data, err := json.Marshal(tx) |
| 203 | if err != nil { |
| 204 | t.Errorf("json.Marshal failed: %v", err) |
| 205 | } |
| 206 | |
| 207 | var parsedTx *Transaction |
| 208 | if err := json.Unmarshal(data, &parsedTx); err != nil { |
| 209 | t.Errorf("json.Unmarshal failed: %v", err) |
| 210 | } |
| 211 | |
| 212 | // compare nonce, price, gaslimit, recipient, amount, payload, V, R, S |
| 213 | if tx.Hash() != parsedTx.Hash() { |
| 214 | t.Errorf("parsed tx differs from original tx, want %v, got %v", tx, parsedTx) |
| 215 | } |
| 216 | if tx.ChainId().Cmp(parsedTx.ChainId()) != 0 { |
| 217 | t.Errorf("invalid chain id, want %d, got %d", tx.ChainId(), parsedTx.ChainId()) |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | // TestTxIsPrivate tests Transaction's SetPrivate() and IsPrivate() functions. |
| 223 | func TestTxIsPrivate(t *testing.T) { |
nothing calls this directly
no test coverage detected