Skip to content
Permalink
Browse files
[DFI-598] Renamed denom (#193)
  • Loading branch information
g3co committed Aug 21, 2020
1 parent 6949e70 commit 476c360e6783b5e56652bc205616f01a60f9456d
Show file tree
Hide file tree
Showing 69 changed files with 297 additions and 297 deletions.
@@ -234,8 +234,8 @@ func NewDnServiceApp(logger log.Logger, db dbm.DB, config *config.VMConfig, invC
app.InitializeVMDataServer(config.DataListen)
app.InitializeVMConnection(config.Address)

// Reduce ConsensusPower reduction coefficient (1 dfi == 1 power unit)
// 1 dfi == 1000000000000000000
// Reduce ConsensusPower reduction coefficient (1 xfi == 1 power unit)
// 1 xfi == 1000000000000000000
sdk.PowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))

var err error
@@ -241,7 +241,7 @@ func TestOracle_CLI(t *testing.T) {
go cliTester.PrintEvents(t, wsChs, "oracle")

nomineeAddr := ct.Accounts["nominee"].Address
assetCode := dnTypes.AssetCode("eth_dfi")
assetCode := dnTypes.AssetCode("eth_xfi")
assetOracle1, assetOracle2, assetOracle3 := ct.Accounts["oracle1"].Address, ct.Accounts["oracle2"].Address, ct.Accounts["oracle3"].Address

// check add asset Tx
@@ -962,8 +962,8 @@ func TestMarkets_CLI(t *testing.T) {
ownerAddr := ct.Accounts["validator1"].Address

// add markets
ct.TxMarketsAdd(ownerAddr, cliTester.DenomBTC, cliTester.DenomDFI).CheckSucceeded()
ct.TxMarketsAdd(ownerAddr, cliTester.DenomETH, cliTester.DenomDFI).CheckSucceeded()
ct.TxMarketsAdd(ownerAddr, cliTester.DenomBTC, cliTester.DenomXFI).CheckSucceeded()
ct.TxMarketsAdd(ownerAddr, cliTester.DenomETH, cliTester.DenomXFI).CheckSucceeded()

// check addMarket Tx
{
@@ -981,7 +981,7 @@ func TestMarkets_CLI(t *testing.T) {

// already existing market
{
tx := ct.TxMarketsAdd(ownerAddr, cliTester.DenomBTC, cliTester.DenomDFI)
tx := ct.TxMarketsAdd(ownerAddr, cliTester.DenomBTC, cliTester.DenomXFI)
tx.CheckFailedWithSDKError(markets.ErrMarketExists)
}
}
@@ -994,14 +994,14 @@ func TestMarkets_CLI(t *testing.T) {
q.CheckFailedWithErrorSubstring("wrong ID")
}

// existing marketID (btc-dfi)
// existing marketID (btc-xfi)
{
q, market := ct.QueryMarketsMarket(dnTypes.NewIDFromUint64(0))
q.CheckSucceeded()

require.Equal(t, market.ID.UInt64(), uint64(0))
require.Equal(t, market.BaseAssetDenom, cliTester.DenomBTC)
require.Equal(t, market.QuoteAssetDenom, cliTester.DenomDFI)
require.Equal(t, market.QuoteAssetDenom, cliTester.DenomXFI)
}
}

@@ -1052,7 +1052,7 @@ func TestMarkets_CLI(t *testing.T) {

// check quoteDenom filter
{
quoteDenom := cliTester.DenomDFI
quoteDenom := cliTester.DenomXFI
q, markets := ct.QueryMarketsList(-1, -1, nil, &quoteDenom)
q.CheckSucceeded()

@@ -1064,7 +1064,7 @@ func TestMarkets_CLI(t *testing.T) {
// check multiple filters
{
baseDeno := cliTester.DenomBTC
quoteDenom := cliTester.DenomDFI
quoteDenom := cliTester.DenomXFI
q, markets := ct.QueryMarketsList(-1, -1, &baseDeno, &quoteDenom)
q.CheckSucceeded()

@@ -1077,12 +1077,12 @@ func TestOrders_CLI(t *testing.T) {
t.Parallel()

const (
DecimalsDFI = "1000000000000000000"
DecimalsXFI = "1000000000000000000"
DecimalsETH = "1000000000000000000"
DecimalsBTC = "100000000"
)

oneDfi := sdk.NewUintFromString(DecimalsDFI)
oneXfi := sdk.NewUintFromString(DecimalsXFI)
oneBtc := sdk.NewUintFromString(DecimalsBTC)
oneEth := sdk.NewUintFromString(DecimalsETH)
accountBalances := []cliTester.StringPair{
@@ -1095,8 +1095,8 @@ func TestOrders_CLI(t *testing.T) {
Value: sdk.NewUint(100000000).Mul(oneEth).String(),
},
{
Key: cliTester.DenomDFI,
Value: sdk.NewUint(100000000).Mul(oneDfi).String(),
Key: cliTester.DenomXFI,
Value: sdk.NewUint(100000000).Mul(oneXfi).String(),
},
}
accountOpts := []cliTester.AccountOption{
@@ -1114,15 +1114,15 @@ func TestOrders_CLI(t *testing.T) {
ownerAddr1 := ct.Accounts[accountOpts[0].Name].Address
ownerAddr2 := ct.Accounts[accountOpts[1].Name].Address
marketID0, marketID1 := dnTypes.NewIDFromUint64(0), dnTypes.NewIDFromUint64(1)
assetCode0, assetCode1 := dnTypes.AssetCode("btc_dfi"), dnTypes.AssetCode("eth_dfi")
assetCode0, assetCode1 := dnTypes.AssetCode("btc_xfi"), dnTypes.AssetCode("eth_xfi")

wsStop, wsChs := ct.CheckWSsSubscribed(false, "TestOrders_CLI", []string{"message.module='orders'"}, 10)
defer wsStop()
go cliTester.PrintEvents(t, wsChs, "orders")

// add market
ct.TxMarketsAdd(ownerAddr1, cliTester.DenomBTC, cliTester.DenomDFI).CheckSucceeded()
ct.TxMarketsAdd(ownerAddr1, cliTester.DenomETH, cliTester.DenomDFI).CheckSucceeded()
ct.TxMarketsAdd(ownerAddr1, cliTester.DenomBTC, cliTester.DenomXFI).CheckSucceeded()
ct.TxMarketsAdd(ownerAddr1, cliTester.DenomETH, cliTester.DenomXFI).CheckSucceeded()

// check AddOrder Tx
{
@@ -516,7 +516,7 @@ func GenTx(msgs []sdk.Msg, accnums []uint64, seq []uint64, priv ...crypto.PrivKe
return auth.NewStdTx(msgs, fee, sigs, memo)
}

// GenDefCoins returns Coins with dfi amount.
// GenDefCoins returns Coins with xfi amount.
func GenDefCoins(t *testing.T) sdk.Coins {
coins, err := sdk.ParseCoins("1000000000000000000000" + dnConfig.MainDenom)
if t != nil {
@@ -77,39 +77,39 @@ module Swap {
const createSwapScriptSrcFmt = `
script {
use {{sender}}::Swap;
use 0x1::DFI;
use 0x1::XFI;
use 0x1::Coins;
use 0x1::Account;
fun main(sender: &signer, amount: u128, price: u128) {
let dfi = Account::withdraw_from_sender(sender, amount);
let xfi = Account::withdraw_from_sender(sender, amount);
// Deposit DFI coins in exchange to BTC.
Swap::create<DFI::T, Coins::BTC>(sender, dfi, price);
// Deposit XFI coins in exchange to BTC.
Swap::create<XFI::T, Coins::BTC>(sender, xfi, price);
}
}
`

const swapSwapScriptSrcFmt = `
script {
use {{sender}}::Swap;
use 0x1::DFI;
use 0x1::XFI;
use 0x1::Coins;
use 0x1::Account;
fun main(sender: &signer, seller: address, price: u128) {
let btc = Account::withdraw_from_sender(sender, price);
// Deposit BTC to swap coins.
Swap::swap<DFI::T, Coins::BTC>(sender, seller, btc);
Swap::swap<XFI::T, Coins::BTC>(sender, seller, btc);
}
}
`

// Test checks Swap Move module without crisis module panic (checks vmauth <-> ccstorage integration).
// 1. Issue BTCs to client2
// 2. Create Swap to exchange client1 DFIs for BTCs (client1's DFIs are locked within Move module)
// 3. Execute Swap transferring BTCs to client1 and DFIs to client2
// 2. Create Swap to exchange client1 XFIs for BTCs (client1's XFIs are locked within Move module)
// 3. Execute Swap transferring BTCs to client1 and XFIs to client2
// 4. Verify balances are updated
func TestIntegApp_Crisis(t *testing.T) {
app, dvmAddr, appStop := NewTestDnAppDVM(t, log.AllowInfoWith("module", "x/crisis"))
@@ -137,19 +137,19 @@ func TestIntegApp_Crisis(t *testing.T) {
return diffs
}

getDfiBtcAccCoins := func(addr sdk.AccAddress) (sdk.Coin, sdk.Coin) {
dfiCoin := sdk.NewCoin(dnConfig.MainDenom, sdk.ZeroInt())
getXfiBtcAccCoins := func(addr sdk.AccAddress) (sdk.Coin, sdk.Coin) {
xfiCoin := sdk.NewCoin(dnConfig.MainDenom, sdk.ZeroInt())
btcCoin := sdk.NewCoin("btc", sdk.ZeroInt())
acc := GetAccountCheckTx(app, addr)
for _, coin := range acc.GetCoins() {
switch coin.Denom {
case dfiCoin.Denom:
dfiCoin = coin
case xfiCoin.Denom:
xfiCoin = coin
case btcCoin.Denom:
btcCoin = coin
}
}
return dfiCoin, btcCoin
return xfiCoin, btcCoin
}

// compile and deploy module
@@ -185,12 +185,12 @@ func TestIntegApp_Crisis(t *testing.T) {
t.Logf(">> Issue 1.0 btc to client2, supply diff:\n%s", strings.Join(verboseSuppliesDiff(suppliesDiff), "\n"))
}

// client1 offers 1.0 DFI for 0.5 BTC
// client1 offers 1.0 XFI for 0.5 BTC
offerAmount, _ := sdk.NewIntFromString("1000000000000000000")
priceAmount, _ := sdk.NewIntFromString("50000000")

// save client1 balances before Swap lock
client1DfiBeforeLock, _ := getDfiBtcAccCoins(client1Addr)
client1XfiBeforeLock, _ := getXfiBtcAccCoins(client1Addr)

// compile and execute create swap script
{
@@ -239,19 +239,19 @@ func TestIntegApp_Crisis(t *testing.T) {

// check client1 balance after Swap lock
{
client1DfiAfterLock, _ := getDfiBtcAccCoins(client1Addr)
t.Logf("client1 before/after Swap lock: %s / %s", client1DfiBeforeLock, client1DfiAfterLock)
client1XfiAfterLock, _ := getXfiBtcAccCoins(client1Addr)
t.Logf("client1 before/after Swap lock: %s / %s", client1XfiBeforeLock, client1XfiAfterLock)

// calc expected amount including fee
expectedAmount := client1DfiBeforeLock.Amount
expectedAmount := client1XfiBeforeLock.Amount
expectedAmount = expectedAmount.Sub(offerAmount)
expectedAmount = expectedAmount.Sub(sdk.OneInt())
require.True(t, client1DfiAfterLock.Amount.Equal(expectedAmount))
require.True(t, client1XfiAfterLock.Amount.Equal(expectedAmount))
}

// save client balances before swap execution
client1DfiBeforeExecution, client1BtcBeforeExecution := getDfiBtcAccCoins(client1Addr)
client2DfiBeforeExecution, client2BtcBeforeExecution := getDfiBtcAccCoins(client2Addr)
client1XfiBeforeExecution, client1BtcBeforeExecution := getXfiBtcAccCoins(client1Addr)
client2XfiBeforeExecution, client2BtcBeforeExecution := getXfiBtcAccCoins(client2Addr)

// compile and execute swap execute script
{
@@ -287,28 +287,28 @@ func TestIntegApp_Crisis(t *testing.T) {

// check balances after Swap execution
{
client1DfiAfterExecution, client1BtcAfterExecution := getDfiBtcAccCoins(client1Addr)
client2DfiAfterExecution, client2BtcAfterExecution := getDfiBtcAccCoins(client2Addr)
client1XfiAfterExecution, client1BtcAfterExecution := getXfiBtcAccCoins(client1Addr)
client2XfiAfterExecution, client2BtcAfterExecution := getXfiBtcAccCoins(client2Addr)

t.Logf("client1 before/after Swap execution: %s / %s, %s / %s", client1DfiBeforeExecution, client1DfiAfterExecution, client1BtcBeforeExecution, client1BtcAfterExecution)
t.Logf("client2 before/after Swap execution: %s / %s, %s / %s", client2DfiBeforeExecution, client2DfiAfterExecution, client2BtcBeforeExecution, client2BtcAfterExecution)
t.Logf("client1 before/after Swap execution: %s / %s, %s / %s", client1XfiBeforeExecution, client1XfiAfterExecution, client1BtcBeforeExecution, client1BtcAfterExecution)
t.Logf("client2 before/after Swap execution: %s / %s, %s / %s", client2XfiBeforeExecution, client2XfiAfterExecution, client2BtcBeforeExecution, client2BtcAfterExecution)

// client1
{
// dfi
require.True(t, client1DfiAfterExecution.IsEqual(client1DfiBeforeExecution))
// xfi
require.True(t, client1XfiAfterExecution.IsEqual(client1XfiBeforeExecution))
// btc
expectedBtcAmount := client1BtcBeforeExecution.Amount
expectedBtcAmount = expectedBtcAmount.Add(priceAmount)
require.True(t, client1BtcAfterExecution.Amount.Equal(expectedBtcAmount))
}
// client2
{
// dfi (including fee)
expectedDfiAmount := client2DfiBeforeExecution.Amount
expectedDfiAmount = expectedDfiAmount.Add(offerAmount)
expectedDfiAmount = expectedDfiAmount.Sub(sdk.OneInt())
require.True(t, client2DfiAfterExecution.Amount.Equal(expectedDfiAmount))
// xfi (including fee)
expectedXfiAmount := client2XfiBeforeExecution.Amount
expectedXfiAmount = expectedXfiAmount.Add(offerAmount)
expectedXfiAmount = expectedXfiAmount.Sub(sdk.OneInt())
require.True(t, client2XfiAfterExecution.Amount.Equal(expectedXfiAmount))
// btc
expectedBtcAmount := client2BtcBeforeExecution.Amount
expectedBtcAmount = expectedBtcAmount.Sub(priceAmount)
@@ -22,11 +22,11 @@ func TestIntegVM_CommunicationUDSOverDocker(t *testing.T) {
const script = `
script {
use 0x1::Account;
use 0x1::DFI;
use 0x1::XFI;
fun main(account: &signer) {
let dfi = Account::withdraw_from_sender<DFI::T>(account, 1);
Account::deposit_to_sender<DFI::T>(account, dfi);
let xfi = Account::withdraw_from_sender<XFI::T>(account, 1);
Account::deposit_to_sender<XFI::T>(account, xfi);
}
}
`
@@ -29,10 +29,10 @@ func TestInteg_ConsensusFailure(t *testing.T) {
const script = `
script {
use 0x1::Account;
use 0x1::DFI;
use 0x1::XFI;
fun main(account: &signer, recipient: address, amount: u128) {
Account::pay_from_sender<DFI::T>(account, recipient, amount);
Account::pay_from_sender<XFI::T>(account, recipient, amount);
}
}
`
@@ -95,11 +95,11 @@ func TestIntegVM_ExecuteScriptViaCLI(t *testing.T) {
const script = `
script {
use 0x1::Account;
use 0x1::DFI;
use 0x1::XFI;
fun main(account: &signer, amount: u128) {
let dfi = Account::withdraw_from_sender<DFI::T>(account, amount);
Account::deposit_to_sender<DFI::T>(account, dfi);
let xfi = Account::withdraw_from_sender<XFI::T>(account, amount);
Account::deposit_to_sender<XFI::T>(account, xfi);
}
}
`
@@ -182,11 +182,11 @@ func TestIntegVM_ExecuteScriptViaREST(t *testing.T) {
const script = `
script {
use 0x1::Account;
use 0x1::DFI;
use 0x1::XFI;
fun main(account: &signer, amount: u128) {
let dfi = Account::withdraw_from_sender<DFI::T>(account, amount);
Account::deposit_to_sender<DFI::T>(account, dfi);
let xfi = Account::withdraw_from_sender<XFI::T>(account, amount);
Account::deposit_to_sender<XFI::T>(account, xfi);
}
}
`
@@ -507,11 +507,11 @@ func TestIntegVM_CommunicationUDS(t *testing.T) {
const script = `
script {
use 0x1::Account;
use 0x1::DFI;
use 0x1::XFI;
fun main(account: &signer) {
let dfi = Account::withdraw_from_sender<DFI::T>(account, 1);
Account::deposit_to_sender<DFI::T>(account, dfi);
let xfi = Account::withdraw_from_sender<XFI::T>(account, 1);
Account::deposit_to_sender<XFI::T>(account, xfi);
}
}
`

0 comments on commit 476c360

Please sign in to comment.