forked from cerc-io/ipld-eth-server
Add Vat tune transformer
This commit is contained in:
@@ -57,6 +57,7 @@ var (
|
||||
tendMethod = GetSolidityMethodSignature(FlipperABI, "tend")
|
||||
vatInitMethod = GetSolidityMethodSignature(VatABI, "init")
|
||||
vatTollMethod = GetSolidityMethodSignature(VatABI, "toll")
|
||||
vatTuneMethod = GetSolidityMethodSignature(VatABI, "tune")
|
||||
|
||||
BiteSignature = GetEventSignature(biteMethod)
|
||||
DealSignature = GetLogNoteSignature(dealMethod)
|
||||
@@ -78,4 +79,5 @@ var (
|
||||
TendFunctionSignature = GetLogNoteSignature(tendMethod)
|
||||
VatInitSignature = GetLogNoteSignature(vatInitMethod)
|
||||
VatTollSignature = GetLogNoteSignature(vatTollMethod)
|
||||
VatTuneSignature = GetLogNoteSignature(vatTuneMethod)
|
||||
)
|
||||
|
||||
@@ -32,3 +32,15 @@ func BigIntToString(value *big.Int) string {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
func GetDataBytesAtIndex(n int, logData []byte) []byte {
|
||||
switch {
|
||||
case n == -1:
|
||||
return logData[len(logData)-DataItemLength:]
|
||||
case n == -2:
|
||||
return logData[len(logData)-(2*DataItemLength) : len(logData)-DataItemLength]
|
||||
case n == -3:
|
||||
return logData[len(logData)-(3*DataItemLength) : len(logData)-(2*DataItemLength)]
|
||||
}
|
||||
return []byte{}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package shared_test
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
var _ = Describe("Shared utilities", func() {
|
||||
Describe("getting data at index", func() {
|
||||
It("gets bytes for the last index in log data", func() {
|
||||
logData := hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c45dd6471a66616b6520696c6b0000000000000000000000000000000000000000000000007d7bee5fcfd8028cf7b00876c5b1421c800561a6000000000000000000000000a3e37186e017747dba34042e83e3f76ad3cce9b00000000000000000000000000f243e26db94b5426032e6dfa6007802dea2a61400000000000000000000000000000000000000000000000000000000000000000000000000000000075bcd15000000000000000000000000000000000000000000000000000000003ade68b1")
|
||||
bigIntBytes := big.NewInt(987654321).Bytes()
|
||||
// big.Int.Bytes() does not include zero padding, but bytes in data index are of fixed length and include zero padding
|
||||
expected := []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
expected = append(expected, bigIntBytes...)
|
||||
|
||||
actual := shared.GetDataBytesAtIndex(-1, logData)
|
||||
|
||||
Expect(expected[:]).To(Equal(actual))
|
||||
})
|
||||
|
||||
It("gets bytes for the second-to-last index in log data", func() {
|
||||
logData := hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c45dd6471a66616b6520696c6b0000000000000000000000000000000000000000000000007d7bee5fcfd8028cf7b00876c5b1421c800561a6000000000000000000000000a3e37186e017747dba34042e83e3f76ad3cce9b00000000000000000000000000f243e26db94b5426032e6dfa6007802dea2a61400000000000000000000000000000000000000000000000000000000000000000000000000000000075bcd15000000000000000000000000000000000000000000000000000000003ade68b1")
|
||||
bigIntBytes := big.NewInt(123456789).Bytes()
|
||||
expected := []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
expected = append(expected, bigIntBytes...)
|
||||
|
||||
actual := shared.GetDataBytesAtIndex(-2, logData)
|
||||
|
||||
Expect(expected[:]).To(Equal(actual))
|
||||
})
|
||||
|
||||
It("gets bytes for the third-to-last index in log data", func() {
|
||||
logData := hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c45dd6471a66616b6520696c6b0000000000000000000000000000000000000000000000007d7bee5fcfd8028cf7b00876c5b1421c800561a6000000000000000000000000a3e37186e017747dba34042e83e3f76ad3cce9b00000000000000000000000000f243e26db94b5426032e6dfa6007802dea2a61400000000000000000000000000000000000000000000000000000000000000000000000000000000075bcd15000000000000000000000000000000000000000000000000000000003ade68b1")
|
||||
addressBytes := common.HexToAddress("0x0F243E26db94B5426032E6DFA6007802Dea2a614").Bytes()
|
||||
// common.address.Bytes() returns [20]byte{}, need [32]byte{}
|
||||
expected := append(addressBytes, []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}...)
|
||||
|
||||
actual := shared.GetDataBytesAtIndex(-3, logData)
|
||||
|
||||
Expect(expected[:]).To(Equal(actual))
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user