Skip to content

Commit

Permalink
Fix L1Message Deep Copy, Complete Bridge Tx Hash test (#269)
Browse files Browse the repository at this point in the history
* deep copy value field, add tx hash test

comment

* typo
  • Loading branch information
maxwolff authored and NazariiDenha committed Apr 17, 2023
1 parent 56d6f4a commit de024eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 35 deletions.
3 changes: 3 additions & 0 deletions core/types/l1_message_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func (tx *L1MessageTx) copy() TxData {
Data: common.CopyBytes(tx.Data),
Sender: tx.Sender,
}
if tx.Value != nil {
cpy.Value.Set(tx.Value)
}
return cpy
}

Expand Down
55 changes: 20 additions & 35 deletions core/types/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,42 +506,27 @@ func TestTransactionCoding(t *testing.T) {
}
}

// TODO: get this to pass
// go test -v -run TestMessageHashMatch
// func TestMessageHashMatch(t *testing.T) {
// // test fails: TODO Fix
// sender := common.HexToAddress("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266")
// to := common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8")
// tx := NewTx(
// &L1MessageTx{
// Sender: sender,
// Nonce: 1,
// Value: big.NewInt(2),
// Gas: 3,
// To: &to,
// Data: []byte{1, 2, 3, 4},
// },
// )

// encoded, err := rlp.EncodeToBytes(tx)
// if err != nil {
// t.Fatal(err)
// }
// fmt.Println("encoded", encoded)

// hash := tx.Hash()

// common.Keccak256Hash
// expectedHash := common.HexToHash("1cebed6d90ef618f60eec1b7edc0df36b298a237c219f0950081acfb72eac6be")
// fmt.Println(hash.Hex())
// fmt.Println(expectedHash.Hex())

// if hash != expectedHash {
// t.Fatal("hashes are not equal")
// }

// }
// make sure that the transaction hash is same as bridge contract
// go test -v -run TestBridgeTxHash
func TestBridgeTxHash(t *testing.T) {
sender := common.HexToAddress("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266")
to := common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8")
tx := NewTx(
&L1MessageTx{
Sender: sender,
Nonce: 1,
Value: big.NewInt(2),
Gas: 3,
To: &to,
Data: []byte{1, 2, 3, 4},
},
)
// assert equal
if tx.Hash() != common.HexToHash("0x1cebed6d90ef618f60eec1b7edc0df36b298a237c219f0950081acfb72eac6be") {
t.Errorf("hash does not match bridge contract")
}

}
func encodeDecodeJSON(tx *Transaction) (*Transaction, error) {
data, err := json.Marshal(tx)
if err != nil {
Expand Down

0 comments on commit de024eb

Please sign in to comment.