Skip to content

Commit

Permalink
[DFI-598] Renamed denom (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
g3co authored Aug 21, 2020
1 parent 6949e70 commit 476c360
Show file tree
Hide file tree
Showing 69 changed files with 297 additions and 297 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions app/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion app/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
64 changes: 32 additions & 32 deletions app/integ_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions app/integ_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
`
Expand Down
22 changes: 11 additions & 11 deletions app/integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
`
Expand Down Expand Up @@ -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);
}
}
`
Expand Down Expand Up @@ -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);
}
}
`
Expand Down Expand Up @@ -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);
}
}
`
Expand Down
Loading

0 comments on commit 476c360

Please sign in to comment.