Skip to content

Commit

Permalink
U/contracts 0.7 (#270)
Browse files Browse the repository at this point in the history
Update contracts to v0.7.0.
  • Loading branch information
maurolacy authored and Mauro Lacy committed Jul 10, 2024
1 parent 253dab4 commit e7658c2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 36 deletions.
34 changes: 26 additions & 8 deletions test/e2e/btc_staking_integration_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ func (s *BTCStakingIntegrationTestSuite) Test2CreateConsumerFinalityProvider() {
fpFromMap, ok := fpMap[czFp.BtcPkHex]
s.True(ok)
s.Equal(fpFromMap.BtcPk.MarshalHex(), czFp.BtcPkHex)
s.Equal(fpFromMap.SlashedBabylonHeight, czFp.SlashedBabylonHeight)
s.Equal(fpFromMap.SlashedBabylonHeight, czFp.SlashedHeight)
s.Equal(fpFromMap.SlashedBtcHeight, czFp.SlashedBtcHeight)
s.Equal(fpFromMap.ConsumerId, czFp.ChainID)
s.Equal(fpFromMap.ConsumerId, czFp.ConsumerID)
}
}

Expand Down Expand Up @@ -228,16 +228,29 @@ func (s *BTCStakingIntegrationTestSuite) Test4ActivateDelegation() {

// assert the fp voting power is updated in the staking contract
var data2FromContract *chain.ConsumerFpsByPowerResponse
fpsWithPower := make([]chain.ConsumerFpInfo, 0)
s.Eventually(func() bool {
data2FromContract, err = czNode.QueryConsumerFpsByPower(stakingContractAddr)
if err != nil {
return false
}
return len(data2FromContract.Fps) == 1
// Filter out no power fps
for _, fp := range data2FromContract.Fps {
if fp.Power > 0 {
fpsWithPower = append(fpsWithPower, fp)
}
}

return len(fpsWithPower) == 1
}, time.Second*20, time.Second)

totalPower := uint64(0)
for _, fp := range data2FromContract.Fps {
totalPower += fp.Power
}

czPowerFromNode := s.getFpTotalPowerFromBabylonNode(consumerFp)
s.Equal(czPowerFromNode, data2FromContract.Fps[0].Power)
s.Equal(czPowerFromNode, totalPower)
}

// Test5UnbondDelegation -
Expand Down Expand Up @@ -319,10 +332,15 @@ func (s *BTCStakingIntegrationTestSuite) Test5UnbondDelegation() {
if err != nil {
return false
}
return len(dataFromContract.Fps) == 1
return len(dataFromContract.Fps) >= 1
}, time.Second*20, time.Second)

s.Equal(uint64(0), dataFromContract.Fps[0].Power) // expect the power to be 0 after unbonding
totalPower := uint64(0)
for _, fp := range dataFromContract.Fps {
totalPower += fp.Power
}

s.Equal(uint64(0), totalPower) // expect the power to be 0 after unbonding
}

// Test6ContractQueries -
Expand Down Expand Up @@ -354,9 +372,9 @@ func (s *BTCStakingIntegrationTestSuite) Test6ContractQueries() {
contractFP, err := czNode.QuerySingleConsumerFp(stakingContractAddr, consumerFp.BtcPk.MarshalHex())
s.NoError(err)
s.Equal(consumerFp.BtcPk.MarshalHex(), contractFP.BtcPkHex)
s.Equal(consumerFp.SlashedBabylonHeight, contractFP.SlashedBabylonHeight)
s.Equal(consumerFp.SlashedBabylonHeight, contractFP.SlashedHeight)
s.Equal(consumerFp.SlashedBtcHeight, contractFP.SlashedBtcHeight)
s.Equal(consumerFp.ConsumerId, contractFP.ChainID)
s.Equal(consumerFp.ConsumerId, contractFP.ConsumerID)

// 4. Query a single BTC delegation from the staking contract
nodeFpDelsSet := nonValidatorNode.QueryFinalityProviderDelegations(consumerFp.BtcPk.MarshalHex())
Expand Down
Binary file modified test/e2e/bytecode/babylon_contract.wasm
Binary file not shown.
Binary file modified test/e2e/bytecode/btc_staking.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion test/e2e/bytecode/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cd74000f248bda1179d218501fb2296577be024c
v0.7.0-rc.2
34 changes: 14 additions & 20 deletions test/e2e/configurer/chain/queries_btcstaking_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ import (
)

type ConsumerFpsResponse struct {
ConsumerFps []SingleConsumerFpResponse `json:"fps"`
ConsumerFps []ConsumerFpResponse `json:"fps"`
}

// SingleConsumerFpResponse represents the finality provider data returned by the contract query.
// ConsumerFpResponse represents the finality provider data returned by the contract query.
// For more details, refer to the following links:
// https://github.com/babylonchain/babylon-contract/blob/v0.5.3/packages/apis/src/btc_staking_api.rs
// https://github.com/babylonchain/babylon-contract/blob/v0.5.3/contracts/btc-staking/src/msg.rs
// https://github.com/babylonchain/babylon-contract/blob/v0.5.3/contracts/btc-staking/schema/btc-staking.json
type SingleConsumerFpResponse struct {
BtcPkHex string `json:"btc_pk_hex"`
SlashedBabylonHeight uint64 `json:"slashed_babylon_height"`
SlashedBtcHeight uint64 `json:"slashed_btc_height"`
ChainID string `json:"chain_id"`
// https://github.com/babylonchain/babylon-contract/blob/v0.7.0/contracts/btc-staking/src/msg.rs
// https://github.com/babylonchain/babylon-contract/blob/v0.7.0/contracts/btc-staking/schema/btc-staking.json
type ConsumerFpResponse struct {
BtcPkHex string `json:"btc_pk_hex"`
SlashedHeight uint64 `json:"slashed_height"`
SlashedBtcHeight uint64 `json:"slashed_btc_height"`
ConsumerID string `json:"consumer_id"`
}

type ConsumerDelegationsResponse struct {
Expand Down Expand Up @@ -77,11 +76,6 @@ type ConsumerFpsByPowerResponse struct {
Fps []ConsumerFpInfo `json:"fps"`
}

type SingleConsumerFpPowerResponse struct {
BtcPkHex string `json:"btc_pk_hex"`
Power uint64 `json:"power"`
}

// QueryConsumerFps queries all finality providers stored in the staking contract
func (n *NodeConfig) QueryConsumerFps(stakingContractAddr string) (*ConsumerFpsResponse, error) {
queryMsg := `{"finality_providers":{}}`
Expand Down Expand Up @@ -146,11 +140,11 @@ func (n *NodeConfig) QueryConsumerDelegationsByFp(stakingContractAddr string, fp
}

// QuerySingleConsumerFp queries a specific finality provider by Bitcoin public key hex
func (n *NodeConfig) QuerySingleConsumerFp(stakingContractAddr string, btcPkHex string) (*SingleConsumerFpResponse, error) {
func (n *NodeConfig) QuerySingleConsumerFp(stakingContractAddr string, btcPkHex string) (*ConsumerFpResponse, error) {
queryMsg := fmt.Sprintf(`{"finality_provider":{"btc_pk_hex":"%s"}}`, btcPkHex)
var (
smartContractResponse *wasmtypes.QuerySmartContractStateResponse
result SingleConsumerFpResponse
result ConsumerFpResponse
err error
)
require.Eventually(n.t, func() bool {
Expand Down Expand Up @@ -208,8 +202,8 @@ func (n *NodeConfig) QueryConsumerFpsByPower(stakingContractAddr string) (*Consu
return &result, err
}

// QuerySingleConsumerFpPower queries a specific finality provider by Bitcoin public key hex and returns its power
func (n *NodeConfig) QuerySingleConsumerFpPower(stakingContractAddr string, fpBtcPkHex string, height *uint64) (*SingleConsumerFpPowerResponse, error) {
// QueryConsumerFpInfo queries a specific finality provider by Bitcoin public key hex and returns its power
func (n *NodeConfig) QueryConsumerFpInfo(stakingContractAddr string, fpBtcPkHex string, height *uint64) (*ConsumerFpInfo, error) {
var queryMsg string
if height != nil {
queryMsg = fmt.Sprintf(`{"finality_provider_info":{"btc_pk_hex":"%s", "height": "%d"}}`, fpBtcPkHex, *height)
Expand All @@ -219,7 +213,7 @@ func (n *NodeConfig) QuerySingleConsumerFpPower(stakingContractAddr string, fpBt

var (
smartContractResponse *wasmtypes.QuerySmartContractStateResponse
result SingleConsumerFpPowerResponse
result ConsumerFpInfo
err error
)
require.Eventually(n.t, func() bool {
Expand Down
7 changes: 1 addition & 6 deletions test/e2e/scripts/copy_local_wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ OUTPUT_FOLDER="$(dirname "$0")/../bytecode"
echo "DEV-only: copy from local built instead of downloading"


M=$(uname -m)
S=${M/arm64/aarch64}
S=${S#x86_64}
S=${S:+-$S}

for CONTRACT in $CONTRACTS
do
cp -f ../../../babylon-contract/artifacts/"${CONTRACT}${S}".wasm "$OUTPUT_FOLDER/${CONTRACT}.wasm"
cp -f ../../../babylon-contract/artifacts/"${CONTRACT}".wasm "$OUTPUT_FOLDER/"
done

cd ../../../babylon-contract
Expand Down
2 changes: 1 addition & 1 deletion x/btcstaking/types/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (ud *BTCUndelegation) ToResponse() (resp *BTCUndelegationResponse) {
return resp
}

// NewFinalityProviderResponse creates a new finality provider response based on the finaliny provider and his voting power.
// NewFinalityProviderResponse creates a new finality provider response based on the finality provider and his voting power.
func NewFinalityProviderResponse(f *FinalityProvider, bbnBlockHeight, votingPower uint64) *FinalityProviderResponse {
return &FinalityProviderResponse{
Description: f.Description,
Expand Down

0 comments on commit e7658c2

Please sign in to comment.