-
Notifications
You must be signed in to change notification settings - Fork 1
/
transaction_test.go
42 lines (30 loc) · 5.6 KB
/
transaction_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package zrx
import (
"encoding/json"
"testing"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// generated from 0x libraries
const KnownSignedTransactionJSON = `{"signerAddress":"0x6ecbe1db9ef729cbe972c83fb886247691fb6beb","salt":"35376205239224606825046077929064122727960011435841421440420799000477844049329","data":"0x9b44d55600000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000004563918244f4000000000000000000000000000000000000000000000000000000000000000003400000000000000000000000005409ed021d9299bf6814279a6a1411a7e866a6310000000000000000000000006ecbe1db9ef729cbe972c83fb886247691fb6beb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000005409ed021d9299bf6814279a6a1411a7e866a6310000000000000000000000000000000000000000000000008ac7230489e800000000000000000000000000000000000000000000000000004563918244f4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005df8034e666d1d2cd5a7adf7b31d1318a84fd8c943469021884352738f54e399ece2637b00000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000220000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000024f47261b0000000000000000000000000871dd7c2b4b25e1aa18728e9d5f2af4c4e431f5c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024f47261b00000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e80820000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000421c2d0f2ee290c5eec6eca75d20f61057c090709a814cc34a5acc67cc512ceb49df530500015f929c1a50448fd3211eccb0bd7354b836b708c8297226c69a16aed602000000000000000000000000000000000000000000000000000000000000","expirationTimeSeconds":"1576534862","gasPrice":"1","signature":"0x1b63fbad28442489e4d7be5d5d11569df73602e7b4a848b9268492ca59c25d751462ed1b3f33a871970608826669181f4546932e0d1975600057a407f02ce9187102"}`
const KnownTransactionSignature = "0x1b63fbad28442489e4d7be5d5d11569df73602e7b4a848b9268492ca59c25d751462ed1b3f33a871970608826669181f4546932e0d1975600057a407f02ce9187102"
const KnownTransactionJSON = `{"signerAddress":"0x6ecbe1db9ef729cbe972c83fb886247691fb6beb","salt":"35376205239224606825046077929064122727960011435841421440420799000477844049329","data":"0x9b44d55600000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000004563918244f4000000000000000000000000000000000000000000000000000000000000000003400000000000000000000000005409ed021d9299bf6814279a6a1411a7e866a6310000000000000000000000006ecbe1db9ef729cbe972c83fb886247691fb6beb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000005409ed021d9299bf6814279a6a1411a7e866a6310000000000000000000000000000000000000000000000008ac7230489e800000000000000000000000000000000000000000000000000004563918244f4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005df8034e666d1d2cd5a7adf7b31d1318a84fd8c943469021884352738f54e399ece2637b00000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000220000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000024f47261b0000000000000000000000000871dd7c2b4b25e1aa18728e9d5f2af4c4e431f5c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024f47261b00000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e80820000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000421c2d0f2ee290c5eec6eca75d20f61057c090709a814cc34a5acc67cc512ceb49df530500015f929c1a50448fd3211eccb0bd7354b836b708c8297226c69a16aed602000000000000000000000000000000000000000000000000000000000000","expirationTimeSeconds":"1576534862","gasPrice":"1"}`
const KnownTransactionHash = "0x423b88708ff03e7a8e18e626ed51cd06183598b37e8c5840e457fb49330de37f"
func TestTransactionComputeHash(t *testing.T) {
var testTransaction Transaction
require.NoError(t, json.Unmarshal([]byte(KnownTransactionJSON), &testTransaction))
hash, err := testTransaction.ComputeHashForChainID(ZeroExTestChainID)
require.NoError(t, err)
assert.Equal(t, KnownTransactionHash, hash.Hex())
}
func TestUnmarshalSignedTx(t *testing.T) {
var signedTx SignedTransaction
var tx Transaction
require.NoError(t, json.Unmarshal([]byte(KnownSignedTransactionJSON), &signedTx))
require.NoError(t, json.Unmarshal([]byte(KnownTransactionJSON), &tx))
knownSig, err := hexutil.Decode(KnownTransactionSignature)
require.NoError(t, err)
assert.Equal(t, tx, signedTx.Transaction)
assert.Equal(t, knownSig, signedTx.Signature)
}