Skip to content

Commit

Permalink
update contract file and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
neitdung committed Jul 27, 2024
1 parent 4ef662b commit 89c5886
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 20 deletions.
4 changes: 3 additions & 1 deletion tests/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type example struct {
ConsumerChain *ibctesting.TestChain
ProviderChain *ibctesting.TestChain
ConsumerApp *app.MeshApp
ProviderApp *app.MeshApp
IbcPath *ibctesting.Path
ProviderDenom string
ConsumerDenom string
Expand All @@ -114,6 +115,7 @@ func setupExampleChains(t *testing.T) example {
ConsumerChain: consChain,
ProviderChain: provChain,
ConsumerApp: consChain.App.(*app.MeshApp),
ProviderApp: provChain.App.(*app.MeshApp),
IbcPath: ibctesting.NewPath(consChain, provChain),
ProviderDenom: sdk.DefaultBondDenom,
ConsumerDenom: sdk.DefaultBondDenom,
Expand All @@ -132,7 +134,7 @@ func setupMeshSecurity(t *testing.T, x example) (*TestConsumerClient, ConsumerCo
x.ConsumerChain.DefaultMsgFees = sdk.NewCoins(sdk.NewCoin(x.ConsumerDenom, math.NewInt(1_000_000)))

providerCli := NewProviderClient(t, x.ProviderChain)
providerContracts := providerCli.BootstrapContracts(x.IbcPath.EndpointA.ConnectionID, converterPortID)
providerContracts := providerCli.BootstrapContracts(x.ProviderApp, x.IbcPath.EndpointA.ConnectionID, converterPortID)

// setup ibc control path: consumer -> provider (direction matters)
x.IbcPath.EndpointB.ChannelConfig = &ibctesting2.ChannelConfig{
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/mvp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func TestMVP(t *testing.T) {
// provider chain
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
execMsg := `{"bond":{}}`
providerCli.MustExecVault(execMsg, sdk.NewInt64Coin(x.ProviderDenom, 100_000_000))
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"100000000"}}}`, x.ProviderDenom)
providerCli.MustExecVault(execMsg)

// then query contract state
assert.Equal(t, 100_000_000, providerCli.QueryVaultFreeBalance())
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/slashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func TestSlashingScenario1(t *testing.T) {
// Provider chain
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
execMsg := `{"bond":{}}`
providerCli.MustExecVault(execMsg, sdk.NewInt64Coin(x.ProviderDenom, 200_000_000))
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"200000000"}}}`, x.ProviderDenom)
providerCli.MustExecVault(execMsg)

// Stake Locally - A user triggers a local staking action to a chosen validator.
myLocalValidatorAddr := sdk.ValAddress(x.ProviderChain.Vals.Validators[0].Address).String()
Expand Down Expand Up @@ -121,8 +121,8 @@ func TestSlashingScenario2(t *testing.T) {
// Provider chain
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
execMsg := `{"bond":{}}`
providerCli.MustExecVault(execMsg, sdk.NewInt64Coin(x.ProviderDenom, 200_000_000))
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"200000000"}}}`, x.ProviderDenom)
providerCli.MustExecVault(execMsg)

// Stake Locally - A user triggers a local staking action to a chosen validator.
myLocalValidatorAddr := sdk.ValAddress(x.ProviderChain.Vals.Validators[0].Address).String()
Expand Down Expand Up @@ -208,8 +208,8 @@ func TestSlashingScenario3(t *testing.T) {
// Provider chain
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
execMsg := `{"bond":{}}`
providerCli.MustExecVault(execMsg, sdk.NewInt64Coin(x.ProviderDenom, 200_000_000))
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"200000000"}}}`, x.ProviderDenom)
providerCli.MustExecVault(execMsg)

// Stake Locally - A user triggers a local staking action to a chosen validator.
myLocalValidatorAddr := sdk.ValAddress(x.ProviderChain.Vals.Validators[0].Address).String()
Expand Down
8 changes: 5 additions & 3 deletions tests/e2e/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ type ProviderContracts struct {
externalStaking sdk.AccAddress
}

func (p *TestProviderClient) BootstrapContracts(connId, portID string) ProviderContracts {
var (
func (p *TestProviderClient) BootstrapContracts(provApp *app.MeshApp, connId, portID string) ProviderContracts { var (
unbondingPeriod = 21 * 24 * 60 * 60 // 21 days - make configurable?
localSlashRatioDoubleSign = "0.20"
localSlashRatioOffline = "0.10"
Expand All @@ -95,7 +94,10 @@ func (p *TestProviderClient) BootstrapContracts(connId, portID string) ProviderC
nativeInitMsg := []byte(fmt.Sprintf(`{"denom": %q, "proxy_code_id": %d, "slash_ratio_dsign": %q, "slash_ratio_offline": %q }`, localTokenDenom, proxyCodeID, localSlashRatioDoubleSign, localSlashRatioOffline))
initMsg := []byte(fmt.Sprintf(`{"denom": %q, "local_staking": {"code_id": %d, "msg": %q}}`, localTokenDenom, nativeStakingCodeID, base64.StdEncoding.EncodeToString(nativeInitMsg)))
vaultContract := InstantiateContract(p.t, p.chain, vaultCodeID, initMsg)

ctx := p.chain.GetContext()
params := provApp.MeshSecProvKeeper.GetParams(ctx)
params.VaultAddress = vaultContract.String()
provApp.MeshSecProvKeeper.SetParams(ctx, params)
// external staking
extStakingCodeID := p.chain.StoreCodeFile(buildPathToWasm("mesh_external_staking.wasm")).CodeID
initMsg = []byte(fmt.Sprintf(
Expand Down
8 changes: 4 additions & 4 deletions tests/starship/mvp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func Test2WayContract(t *testing.T) {
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
fmt.Println("provider chain: deposit vault denom to provide some collateral to account")
execMsg := `{"bond":{}}`
vault, err := providerClient1.MustExecVault(execMsg, sdk.NewInt64Coin(providerClient1.Chain.Denom, 100_000_000))
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"100000000"}}}`, providerClient1.Chain.Denom)
vault, err := providerClient1.MustExecVault(execMsg)
require.NoError(t, err)
require.NotEmpty(t, vault)

Expand Down Expand Up @@ -130,8 +130,8 @@ func Test2WayContract(t *testing.T) {
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
fmt.Println("provider chain: deposit vault denom to provide some collateral to account")
execMsg = `{"bond":{}}`
vault, err = providerClient2.MustExecVault(execMsg, sdk.NewInt64Coin(providerClient2.Chain.Denom, 100_000_000))
execMsg = fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"100000000"}}}`, providerClient2.Chain.Denom)
vault, err = providerClient2.MustExecVault(execMsg)
require.NoError(t, err)
require.NotEmpty(t, vault)

Expand Down
6 changes: 3 additions & 3 deletions tests/testdata/copy_local_wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ command -v shellcheck > /dev/null && shellcheck "$0"

echo "DEV-only: copy from local built instead of downloading"

for contract in external_staking mesh_converter mesh_native_staking mesh_native_staking_proxy mesh_simple_price_feed \
for contract in mesh_external_staking mesh_converter mesh_native_staking mesh_native_staking_proxy mesh_simple_price_feed \
mesh_vault mesh_virtual_staking ; do
cp -f ../../../../mesh-security/artifacts/${contract}.wasm .
cp -f ../../../mesh-security/artifacts/${contract}.wasm .
gzip -fk ${contract}.wasm
rm -f ${contract}.wasm
done

cd ../../../../mesh-security
cd ../../../mesh-security
tag=$(git rev-parse HEAD)
cd -
rm -f version.txt
Expand Down
Binary file modified tests/testdata/mesh_converter.wasm.gz
Binary file not shown.
Binary file modified tests/testdata/mesh_external_staking.wasm.gz
Binary file not shown.
Binary file modified tests/testdata/mesh_native_staking.wasm.gz
Binary file not shown.
Binary file modified tests/testdata/mesh_native_staking_proxy.wasm.gz
Binary file not shown.
Binary file modified tests/testdata/mesh_simple_price_feed.wasm.gz
Binary file not shown.
Binary file modified tests/testdata/mesh_vault.wasm.gz
Binary file not shown.
Binary file modified tests/testdata/mesh_virtual_staking.wasm.gz
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 @@
v0.10.0-alpha.1
34284a38601ff132e8d7b5594a87794faa71bbed

0 comments on commit 89c5886

Please sign in to comment.