|
47 | 47 | conf.EcotoneTime = &time
|
48 | 48 | return &conf
|
49 | 49 | }()
|
| 50 | + isthmusTestConfig = func() *params.ChainConfig { |
| 51 | + conf := *bedrockGenesisTestConfig // copy the config |
| 52 | + time := uint64(0) |
| 53 | + conf.IsthmusTime = &time |
| 54 | + return &conf |
| 55 | + }() |
50 | 56 |
|
51 | 57 | legacyReceipt = &Receipt{
|
52 | 58 | Status: ReceiptStatusFailed,
|
@@ -767,6 +773,78 @@ func getOptimismEcotoneTxReceipts(l1AttributesPayload []byte, l1GasPrice, l1Blob
|
767 | 773 | return txs, receipts
|
768 | 774 | }
|
769 | 775 |
|
| 776 | +func getOptimismIsthmusTxReceipts(l1AttributesPayload []byte, l1GasPrice, l1BlobGasPrice, l1GasUsed, l1Fee *big.Int, baseFeeScalar, blobBaseFeeScalar, operatorFeeScalar, operatorFeeConstant *uint64) ([]*Transaction, []*Receipt) { |
| 777 | + // Create a few transactions to have receipts for |
| 778 | + txs := Transactions{ |
| 779 | + NewTx(&DepositTx{ |
| 780 | + To: nil, // contract creation |
| 781 | + Value: big.NewInt(6), |
| 782 | + Gas: 50, |
| 783 | + Data: l1AttributesPayload, |
| 784 | + }), |
| 785 | + emptyTx, |
| 786 | + } |
| 787 | + |
| 788 | + // Create the corresponding receipts |
| 789 | + receipts := Receipts{ |
| 790 | + &Receipt{ |
| 791 | + Type: DepositTxType, |
| 792 | + PostState: common.Hash{5}.Bytes(), |
| 793 | + CumulativeGasUsed: 50 + 15, |
| 794 | + Logs: []*Log{ |
| 795 | + { |
| 796 | + Address: common.BytesToAddress([]byte{0x33}), |
| 797 | + // derived fields: |
| 798 | + BlockNumber: blockNumber.Uint64(), |
| 799 | + TxHash: txs[0].Hash(), |
| 800 | + TxIndex: 0, |
| 801 | + BlockHash: blockHash, |
| 802 | + Index: 0, |
| 803 | + }, |
| 804 | + { |
| 805 | + Address: common.BytesToAddress([]byte{0x03, 0x33}), |
| 806 | + // derived fields: |
| 807 | + BlockNumber: blockNumber.Uint64(), |
| 808 | + TxHash: txs[0].Hash(), |
| 809 | + TxIndex: 0, |
| 810 | + BlockHash: blockHash, |
| 811 | + Index: 1, |
| 812 | + }, |
| 813 | + }, |
| 814 | + TxHash: txs[0].Hash(), |
| 815 | + ContractAddress: common.HexToAddress("0x3bb898b4bbe24f68a4e9be46cfe72d1787fd74f4"), |
| 816 | + GasUsed: 65, |
| 817 | + EffectiveGasPrice: big.NewInt(0), |
| 818 | + BlockHash: blockHash, |
| 819 | + BlockNumber: blockNumber, |
| 820 | + TransactionIndex: 0, |
| 821 | + DepositNonce: &depNonce1, |
| 822 | + }, |
| 823 | + &Receipt{ |
| 824 | + Type: LegacyTxType, |
| 825 | + EffectiveGasPrice: big.NewInt(0), |
| 826 | + PostState: common.Hash{4}.Bytes(), |
| 827 | + CumulativeGasUsed: 10, |
| 828 | + Logs: []*Log{}, |
| 829 | + // derived fields: |
| 830 | + TxHash: txs[1].Hash(), |
| 831 | + GasUsed: 18446744073709551561, |
| 832 | + BlockHash: blockHash, |
| 833 | + BlockNumber: blockNumber, |
| 834 | + TransactionIndex: 1, |
| 835 | + L1GasPrice: l1GasPrice, |
| 836 | + L1BlobBaseFee: l1BlobGasPrice, |
| 837 | + L1GasUsed: l1GasUsed, |
| 838 | + L1Fee: l1Fee, |
| 839 | + L1BaseFeeScalar: baseFeeScalar, |
| 840 | + L1BlobBaseFeeScalar: blobBaseFeeScalar, |
| 841 | + OperatorFeeScalar: operatorFeeScalar, |
| 842 | + OperatorFeeConstant: operatorFeeConstant, |
| 843 | + }, |
| 844 | + } |
| 845 | + return txs, receipts |
| 846 | +} |
| 847 | + |
770 | 848 | func getOptimismTxReceipts(l1AttributesPayload []byte, l1GasPrice, l1GasUsed, l1Fee *big.Int, feeScalar *big.Float) ([]*Transaction, []*Receipt) {
|
771 | 849 | // Create a few transactions to have receipts for
|
772 | 850 | txs := Transactions{
|
@@ -887,6 +965,56 @@ func TestDeriveOptimismEcotoneTxReceipts(t *testing.T) {
|
887 | 965 | diffReceipts(t, receipts, derivedReceipts)
|
888 | 966 | }
|
889 | 967 |
|
| 968 | +func TestDeriveOptimismIsthmusTxReceipts(t *testing.T) { |
| 969 | + // Isthmus style l1 attributes with baseFeeScalar=2, blobBaseFeeScalar=3, baseFee=1000*1e6, blobBaseFee=10*1e6, operatorFeeScalar=7, operatorFeeConstant=9 |
| 970 | + payload := common.Hex2Bytes("098999be000000020000000300000000000004d200000000000004d200000000000004d2000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000000098968000000000000000000000000000000000000000000000000000000000000004d200000000000000000000000000000000000000000000000000000000000004d255c6fb7c116fb15b44847d04") |
| 971 | + // the parameters we use below are defined in rollup_test.go |
| 972 | + baseFeeScalarUint64 := baseFeeScalar.Uint64() |
| 973 | + blobBaseFeeScalarUint64 := blobBaseFeeScalar.Uint64() |
| 974 | + operatorFeeScalarUint64 := operatorFeeScalar.Uint64() |
| 975 | + operatorFeeConstantUint64 := operatorFeeConstant.Uint64() |
| 976 | + txs, receipts := getOptimismIsthmusTxReceipts(payload, baseFee, blobBaseFee, minimumFjordGas, fjordFee, &baseFeeScalarUint64, &blobBaseFeeScalarUint64, &operatorFeeScalarUint64, &operatorFeeConstantUint64) |
| 977 | + |
| 978 | + // Re-derive receipts. |
| 979 | + baseFee := big.NewInt(1000) |
| 980 | + derivedReceipts := clearComputedFieldsOnReceipts(receipts) |
| 981 | + // Should error out if we try to process this with a pre-Isthmus config |
| 982 | + err := Receipts(derivedReceipts).DeriveFields(bedrockGenesisTestConfig, blockHash, blockNumber.Uint64(), 0, baseFee, nil, txs) |
| 983 | + if err == nil { |
| 984 | + t.Fatalf("expected error from deriving isthmus receipts with pre-isthmus config, got none") |
| 985 | + } |
| 986 | + |
| 987 | + err = Receipts(derivedReceipts).DeriveFields(isthmusTestConfig, blockHash, blockNumber.Uint64(), 0, baseFee, nil, txs) |
| 988 | + if err != nil { |
| 989 | + t.Fatalf("DeriveFields(...) = %v, want <nil>", err) |
| 990 | + } |
| 991 | + diffReceipts(t, receipts, derivedReceipts) |
| 992 | +} |
| 993 | + |
| 994 | +func TestDeriveOptimismIsthmusTxReceiptsNoOperatorFee(t *testing.T) { |
| 995 | + // Isthmus style l1 attributes with baseFeeScalar=2, blobBaseFeeScalar=3, baseFee=1000*1e6, blobBaseFee=10*1e6, operatorFeeScalar=7, operatorFeeConstant=9 |
| 996 | + payload := common.Hex2Bytes("098999be000000020000000300000000000004d200000000000004d200000000000004d2000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000000098968000000000000000000000000000000000000000000000000000000000000004d200000000000000000000000000000000000000000000000000000000000004d2000000000000000000000000") |
| 997 | + // the parameters we use below are defined in rollup_test.go |
| 998 | + baseFeeScalarUint64 := baseFeeScalar.Uint64() |
| 999 | + blobBaseFeeScalarUint64 := blobBaseFeeScalar.Uint64() |
| 1000 | + txs, receipts := getOptimismIsthmusTxReceipts(payload, baseFee, blobBaseFee, minimumFjordGas, fjordFee, &baseFeeScalarUint64, &blobBaseFeeScalarUint64, nil, nil) |
| 1001 | + |
| 1002 | + // Re-derive receipts. |
| 1003 | + baseFee := big.NewInt(1000) |
| 1004 | + derivedReceipts := clearComputedFieldsOnReceipts(receipts) |
| 1005 | + // Should error out if we try to process this with a pre-Isthmus config |
| 1006 | + err := Receipts(derivedReceipts).DeriveFields(bedrockGenesisTestConfig, blockHash, blockNumber.Uint64(), 0, baseFee, nil, txs) |
| 1007 | + if err == nil { |
| 1008 | + t.Fatalf("expected error from deriving isthmus receipts with pre-isthmus config, got none") |
| 1009 | + } |
| 1010 | + |
| 1011 | + err = Receipts(derivedReceipts).DeriveFields(isthmusTestConfig, blockHash, blockNumber.Uint64(), 0, baseFee, nil, txs) |
| 1012 | + if err != nil { |
| 1013 | + t.Fatalf("DeriveFields(...) = %v, want <nil>", err) |
| 1014 | + } |
| 1015 | + diffReceipts(t, receipts, derivedReceipts) |
| 1016 | +} |
| 1017 | + |
890 | 1018 | func diffReceipts(t *testing.T, receipts, derivedReceipts []*Receipt) {
|
891 | 1019 | // Check diff of receipts against derivedReceipts.
|
892 | 1020 | r1, err := json.MarshalIndent(receipts, "", " ")
|
|
0 commit comments