-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b03500a
commit 8473deb
Showing
13 changed files
with
163 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package interchaintest | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/strangelove-ventures/interchaintest/v7" | ||
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" | ||
"github.com/stretchr/testify/assert" | ||
|
||
helpers "github.com/CosmosContracts/juno/tests/interchaintest/helpers" | ||
) | ||
|
||
// TestJunoBurnModule ensures the junoburn module register and execute sharing functions work properly on smart contracts. | ||
// This is required due to how x/mint handles minting tokens for the target supply. | ||
// It is purely for developers ::BurnTokens to function as expected. | ||
func TestJunoBurnModule(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Base setup | ||
chains := CreateThisBranchChain(t, 1, 0) | ||
ic, ctx, _, _ := BuildInitialChain(t, chains) | ||
|
||
// Chains | ||
juno := chains[0].(*cosmos.CosmosChain) | ||
|
||
nativeDenom := juno.Config().Denom | ||
|
||
// Users | ||
users := interchaintest.GetAndFundTestUsers(t, ctx, "default", int64(10_000_000), juno, juno) | ||
user := users[0] | ||
|
||
// Upload & init contract | ||
_, contractAddr := helpers.SetupContract(t, ctx, juno, user.KeyName(), "contracts/cw_testburn.wasm", `{}`) | ||
|
||
// get balance before execute | ||
balance, err := juno.GetBalance(ctx, user.FormattedAddress(), nativeDenom) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// execute burn of tokens | ||
burnAmt := int64(1_000_000) | ||
helpers.ExecuteMsgWithAmount(t, ctx, juno, user, contractAddr, strconv.Itoa(int(burnAmt))+nativeDenom, `{"burn_token":{}}`) | ||
|
||
// verify it is down 1_000_000 tokens since the burn | ||
updatedBal, err := juno.GetBalance(ctx, user.FormattedAddress(), nativeDenom) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Verify the funds were sent, and burned. | ||
fmt.Println(balance, updatedBal) | ||
assert.Equal(t, burnAmt, balance-updatedBal, fmt.Sprintf("balance should be %d less than updated balance", burnAmt)) | ||
|
||
t.Cleanup(func() { | ||
_ = ic.Close() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# x/burn | ||
|
||
This is a 'module' used solely to burn tokens properly in line with our x/mint module requirements. | ||
|
||
## Burn address | ||
|
||
- juno1mj7t69y4r2adl3cnuq8y9uundkzawvx6avu7nj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package burn | ||
|
||
import ( | ||
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" | ||
|
||
mintkeeper "github.com/CosmosContracts/juno/v18/x/mint/keeper" | ||
) | ||
|
||
// used to override Wasmd's NewBurnCoinMessageHandler | ||
|
||
type BurnerWasmPlugin struct { | ||
bk bankkeeper.Keeper | ||
mk mintkeeper.Keeper | ||
} | ||
|
||
var _ wasmtypes.Burner = &BurnerWasmPlugin{} | ||
|
||
func NewBurnerPlugin(bk bankkeeper.Keeper, mk mintkeeper.Keeper) *BurnerWasmPlugin { | ||
return &BurnerWasmPlugin{bk: bk, mk: mk} | ||
} | ||
|
||
func (k *BurnerWasmPlugin) BurnCoins(ctx sdk.Context, _ string, amt sdk.Coins) error { | ||
// first, try to burn the coins on bank module | ||
err := k.bk.BurnCoins(ctx, ModuleName, amt) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// get mint params | ||
params := k.mk.GetParams(ctx) | ||
|
||
// loop the burned coins | ||
for _, amount := range amt { | ||
// if we are burning mint denom, reduce the target staking supply | ||
if amount.Denom == params.MintDenom { | ||
if err := k.mk.ReduceTargetSupply(ctx, amount); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (k *BurnerWasmPlugin) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, _ string, amt sdk.Coins) error { | ||
return k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, ModuleName, amt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package burn | ||
|
||
const ( | ||
ModuleName = "junoburn" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters