Skip to content

Commit

Permalink
e2e test on btc headers
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Aug 13, 2024
1 parent f386fed commit 84bbd72
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
10 changes: 9 additions & 1 deletion tests/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,20 @@ func (s *BabylonSDKTestSuite) Test1ContractDeployment() {

// TestExample is an example test case
func (s *BabylonSDKTestSuite) Test2MockConsumerFpDelegation() {
// generate headers
headersMsg := types.GenBTCHeadersMsg()
headersMsgBytes, err := json.Marshal(headersMsg)
s.NoError(err)
// send headers to the Babylon contract
res, err := s.ConsumerCli.Exec(s.ConsumerContract.Babylon, headersMsgBytes)
s.NoError(err, res)

testMsg = types.GenExecMessage()
msgBytes, err := json.Marshal(testMsg)
s.NoError(err)

// send msg to BTC staking contract via admin account
res, err := s.ConsumerCli.Exec(s.ConsumerContract.BTCStaking, msgBytes)
res, err = s.ConsumerCli.Exec(s.ConsumerContract.BTCStaking, msgBytes)
s.NoError(err, res)

// ensure the finality provider is on consumer chain
Expand Down
40 changes: 40 additions & 0 deletions tests/e2e/types/datagen.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ import (
"github.com/stretchr/testify/require"
)

func GenBTCHeadersMsg() BabylonExecuteMsg {
r := rand.New(rand.NewSource(time.Now().Unix()))

chain := datagen.NewBTCHeaderChainWithLength(r, 0, 0, 10)
headers := []BtcHeader{}
for _, header := range chain.Headers {
headers = append(headers, BtcHeader{
Version: header.Version,
PrevBlockhash: header.PrevBlock.String(),
MerkleRoot: header.MerkleRoot.String(),
Time: uint32(header.Timestamp.Unix()),
Bits: header.Bits,
Nonce: header.Nonce,
})
}

return BabylonExecuteMsg{
BtcHeaders: BTCHeadersMsg{
Headers: headers,
},
}
}

func GenExecMessage() ExecuteMessage {
_, newDel := genBTCDelegation()

Expand Down Expand Up @@ -240,6 +263,23 @@ type UnbondedBtcDelegation struct {
// Define fields as needed
}

type BabylonExecuteMsg struct {
BtcHeaders BTCHeadersMsg `json:"btc_headers"`
}

type BTCHeadersMsg struct {
Headers []BtcHeader `json:"headers"`
}

type BtcHeader struct {
Version int32 `json:"version"`
PrevBlockhash string `json:"prev_blockhash"`
MerkleRoot string `json:"merkle_root"`
Time uint32 `json:"time"`
Bits uint32 `json:"bits"`
Nonce uint32 `json:"nonce"`
}

type ExecuteMessage struct {
BtcStaking BtcStaking `json:"btc_staking"`
}
Expand Down
Binary file modified tests/testdata/btc_staking.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/testdata/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8023e116ba8fc20c6f2efd4b1cbc08739d38b565
44b2d1209869dd1909b957358238975e086f48dd

0 comments on commit 84bbd72

Please sign in to comment.