Skip to content

Commit

Permalink
Update Go Contracts (#119)
Browse files Browse the repository at this point in the history
Co-authored-by: Trajan0x <[email protected]>
  • Loading branch information
trajan0x and trajan0x authored Aug 23, 2022
1 parent ee1ee99 commit 7f9e47a
Show file tree
Hide file tree
Showing 25 changed files with 1,876 additions and 1,279 deletions.
3 changes: 2 additions & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ ignore:
# solidity test files
- '*/test/*.sol'
- '*/lib/*.sol'
- 'packages/contracts/libs/*.sol'
- 'packages/contracts/contracts/libs/*.sol'
- 'packages/contracts/test/*.sol'
189 changes: 181 additions & 8 deletions core/contracts/attestationcollector/attestationcollector.abigen.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

209 changes: 191 additions & 18 deletions core/contracts/destination/destination.abigen.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/contracts/destination/destination.contractinfo.json

Large diffs are not rendered by default.

213 changes: 193 additions & 20 deletions core/contracts/notarymanager/notarymanager.abigen.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

211 changes: 192 additions & 19 deletions core/contracts/origin/origin.abigen.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/contracts/origin/origin.contractinfo.json

Large diffs are not rendered by default.

385 changes: 279 additions & 106 deletions core/contracts/test/attestationharness/attestationharness.abigen.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

211 changes: 192 additions & 19 deletions core/contracts/test/destinationharness/destinationharness.abigen.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

406 changes: 123 additions & 283 deletions core/contracts/test/headerharness/headerharness.abigen.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

489 changes: 187 additions & 302 deletions core/contracts/test/messageharness/messageharness.abigen.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

213 changes: 193 additions & 20 deletions core/contracts/test/originharness/originharness.abigen.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

575 changes: 121 additions & 454 deletions core/contracts/test/tipsharness/tipsharness.abigen.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

15 changes: 4 additions & 11 deletions core/types/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,8 @@ func EncodeHeader(header Header) ([]byte, error) {
// messageEncoder contains the binary structore of the message.
type messageEncoder struct {
Version uint16
HeaderOffset uint16
TipsOffset uint16
BodyOffset uint16
HeaderLength uint16
TipsLength uint16
}

// EncodeMessage encodes a message.
Expand All @@ -196,16 +195,10 @@ func EncodeMessage(m Message) ([]byte, error) {
return []byte{}, fmt.Errorf("could not encode tips: %w", err)
}

tipsOffset := headerOffset + uint16(len(encodedHeader))
bodyOffset := tipsOffset + uint16(len(encodedTips))

// payload := append(append(encodedHeader, encodedTips...), m.Body()...)

newMessage := messageEncoder{
Version: m.Version(),
HeaderOffset: headerOffset,
TipsOffset: tipsOffset,
BodyOffset: bodyOffset,
HeaderLength: uint16(len(encodedHeader)),
TipsLength: uint16(len(encodedTips)),
}

buf := new(bytes.Buffer)
Expand Down
8 changes: 4 additions & 4 deletions core/types/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type messageImpl struct {

const messageVersion uint16 = 1

const headerOffset uint16 = 8
const headerOffset uint16 = 6

// NewMessage creates a new message from fields passed in.
func NewMessage(header Header, tips Tips, body []byte) Message {
Expand Down Expand Up @@ -80,14 +80,14 @@ func DecodeMessage(message []byte) (Message, error) {
return nil, fmt.Errorf("could not parse encoded: %w", err)
}

rawHeader := message[encoded.HeaderOffset:encoded.TipsOffset]
rawHeader := message[headerOffset : encoded.HeaderLength+headerOffset]

header, err := DecodeHeader(rawHeader)
if err != nil {
return nil, fmt.Errorf("could not decode header: %w", err)
}

rawTips := message[encoded.TipsOffset:encoded.BodyOffset]
rawTips := message[headerOffset+encoded.HeaderLength : headerOffset+encoded.HeaderLength+encoded.TipsLength]
unmarshalledTips, err := DecodeTips(rawTips)
if err != nil {
return nil, fmt.Errorf("could not decode unmarshalledTips: %w", err)
Expand All @@ -100,7 +100,7 @@ func DecodeMessage(message []byte) (Message, error) {
return nil, fmt.Errorf("message too small, expected at least %d, got %d", dataSize, len(message))
}

rawBody := message[encoded.BodyOffset:]
rawBody := message[headerOffset+encoded.HeaderLength+encoded.TipsLength:]

decoded := messageImpl{
version: encoded.Version,
Expand Down
6 changes: 3 additions & 3 deletions core/types/parity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ func TestMessageEncodeParity(t *testing.T) {
Nil(t, err)
Equal(t, version, types.MessageVersion)

headerOffset, err := messageContract.HeaderOffset(&bind.CallOpts{Context: ctx})
headerOffset, err := messageContract.OffsetHeader(&bind.CallOpts{Context: ctx})
Nil(t, err)
Equal(t, headerOffset, types.HeaderOffset)
Equal(t, headerOffset, big.NewInt(int64(types.HeaderOffset)))

// generate some fake data
origin := gofakeit.Uint32()
Expand All @@ -160,7 +160,7 @@ func TestMessageEncodeParity(t *testing.T) {
proverTip := randomUint96BigInt(t)
executorTip := randomUint96BigInt(t)

formattedMessage, err := messageContract.FormatMessage(&bind.CallOpts{Context: ctx}, origin, sender, nonce, destination, recipient, optimisticSeconds, notaryTip, broadcasterTip, proverTip, executorTip, body)
formattedMessage, err := messageContract.FormatMessage0(&bind.CallOpts{Context: ctx}, origin, sender, nonce, destination, recipient, optimisticSeconds, notaryTip, broadcasterTip, proverTip, executorTip, body)
Nil(t, err)

decodedMessage, err := types.DecodeMessage(formattedMessage)
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"scripts": {
"build": "yarn build:contracts && yarn build:typescript && yarn build:go",
"build:go": "rimraf ./flattened/* && yarn sol-merger \"./contracts/**.sol\" ./flattened --export-plugin SPDXLicenseRemovePlugin & yarn sol-merger \"./test/harnesses/**.sol\" ./flattened --export-plugin SPDXLicenseRemovePlugin",
"build:go": "rimraf ./flattened/* && yarn sol-merger \"./contracts/**.sol\" ./flattened --export-plugin SPDXLicenseRemovePlugin && yarn sol-merger \"./test/harnesses/**.sol\" ./flattened --export-plugin SPDXLicenseRemovePlugin && yarn sol-merger \"./test/harnesses/libs/**.sol\" ./flattened --export-plugin SPDXLicenseRemovePlugin",
"build:contracts": "forge build",
"build:slither": "hardhat compile",
"build:typescript": "typechain --target ethers-v5 'artifacts/**/*json'",
Expand Down

0 comments on commit 7f9e47a

Please sign in to comment.