Skip to content

Commit e2ea8c2

Browse files
authored
[DFI-584] GLAV lib inegration (#190)
* [DFI-584] Mod ccstorage: changed hardcode vm path to generated by GLAV lib * [DFI-584] Mod ccstorage: removed vm path properties * [DFI-584] Mod ccstorage: refactoring newBalance method * [DFI-584] Fixed go.mod * [DFI-584] Fixed glav version in go.mod * [DFI-584] merge fix * [DFI-584] fixed doc and hardcoded test path * [DFI-584] fixed paddings * [DFI-584] fixed typo * [DFI-584] fixed InfoPathHex method
1 parent b8ca557 commit e2ea8c2

26 files changed

+103
-353
lines changed

app/common_currencies_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,9 @@ func GetAllSupplies(t *testing.T, app *DnServiceApp, ctx sdk.Context) AllSupplie
225225

226226
// CreateCurrency creates currency with random VM paths.
227227
func CreateCurrency(t *testing.T, app *DnServiceApp, ccDenom string, ccDecimals uint8) {
228-
_, balancePathHex := GenerateRandomBytes(10)
229-
_, infoPathHex := GenerateRandomBytes(10)
230-
231228
params := ccstorage.CurrencyParams{
232-
Denom: ccDenom,
233-
Decimals: ccDecimals,
234-
BalancePathHex: balancePathHex,
235-
InfoPathHex: infoPathHex,
229+
Denom: ccDenom,
230+
Decimals: ccDecimals,
236231
}
237232

238233
app.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{ChainID: chainID, Height: app.LastBlockHeight() + 1}})

app/common_orderbook_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,9 @@ func (tester *OrderBookTester) RegisterMarket(ownerAddr sdk.AccAddress, baseDeno
114114
ctx := GetContext(tester.app, false)
115115

116116
registerCurrency := func(denom string, decimals uint8) {
117-
_, balancePathHex := GenerateRandomBytes(10)
118-
_, infoPathHex := GenerateRandomBytes(10)
119-
120117
ccParams := ccstorage.CurrencyParams{
121-
Denom: denom,
122-
Decimals: decimals,
123-
BalancePathHex: balancePathHex,
124-
InfoPathHex: infoPathHex,
118+
Denom: denom,
119+
Decimals: decimals,
125120
}
126121
err := tester.app.ccKeeper.CreateCurrency(ctx, ccParams)
127122
require.NoError(tester.t, err, "adding currency for denom: %s", denom)

app/integ_gov_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"path"
99
"testing"
1010

11+
"github.com/dfinance/glav"
1112
"github.com/stretchr/testify/require"
1213

1314
"github.com/dfinance/dnode/cmd/config"
@@ -54,10 +55,11 @@ const govScript = `
5455
`
5556

5657
func TestIntegGov_StdlibUpdate(t *testing.T) {
57-
const (
58-
moduleAddr = "0000000000000000000000000000000000000001"
59-
modulePath = "0058e1e3e2f8edf7df0c4b1ab8c1c8ec661b3210b29c85b1449ac6214c6476b0e8"
60-
)
58+
var moduleAddressByte [20]byte
59+
copy(moduleAddressByte[:], common_vm.StdLibAddress[:20])
60+
61+
modulePath := hex.EncodeToString(glav.ModuleAccessVector(moduleAddressByte, "Foo"))
62+
moduleAddr := hex.EncodeToString(common_vm.StdLibAddress)
6163

6264
ct := cliTester.New(
6365
t,
@@ -212,8 +214,9 @@ func TestIntegGov_RegisterCurrency(t *testing.T) {
212214
// New currency info
213215
crDenom := "tst"
214216
crDecimals := uint8(8)
215-
crBalancePathHex := "A1A2A3A4A5A6A7A8A9ABACADAEAFB1B2B3B4B5B6B7B8B9BABBBCBDBEBFC1C2C3C4"
216-
crInfoPathHex := "0102030405060708090A0B0C0D0E0FA1A2A3A4A5A6A7A8A9AAABACADAEAFB1B2B3"
217+
218+
crBalancePathHex := hex.EncodeToString(glav.BalanceVector(crDenom))
219+
crInfoPathHex := hex.EncodeToString(glav.CurrencyInfoVector(crDenom))
217220

218221
// Check invalid arguments for AddCurrencyProposal Tx
219222
{

docs/genesis_generation.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ It should be done before the next commands, refer to the tutorial **[how to init
6262
The following commands might be omitted as [`xfi`, `eth`, `usdt`, `btc`] currencies already exist in the default generated genesis above.
6363
Currencies can be added to the chain later using `gov` proposals.
6464

65-
dnode set-currency xfi 18 01226844e85ad6e3867f4ff1a4300e71ed6057538631a5a5330512772b7104b585 01b9ed21c23abf8c7a53fb868a36e106d45394c30127fb722f8dd2d45aae719585
66-
dnode set-currency eth 18 0138f4f2895881c804de0e57ced1d44f02e976f9c6561c889f7b7eef8e660d2c9a 012a00668b5325f832c28a24eb83dffa8295170c80345fbfbf99a5263f962c76f4
67-
dnode set-currency usdt 6 01a04b6467f35792e0fda5638a509cc807b3b289a4e0ea10794c7db5dc1a63d481 01d058943a984bc02bc4a8547e7c0d780c59334e9aa415b90c87e70d140b2137b8
68-
dnode set-currency btc 8 019a2b233aea4cab2e5b6701280f8302be41ea5731af93858fd96e038499eda072 019fdf92aeba5356ec5455b1246c2e1b71d5c7192c6e5a1b50444dafaedc1c40c9
65+
dnode set-currency xfi 18
66+
dnode set-currency eth 18
67+
dnode set-currency usdt 6
68+
dnode set-currency btc 8
6969

7070
We can also add DEX markets to genesis (markets can be added later via non-genesis Tx command as well):
7171

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/containerd/continuity v0.0.0-20200228182428-0f16d7a0959c // indirect
1212
github.com/cosmos/cosmos-sdk v0.39.0
1313
github.com/dfinance/dvm-proto/go v0.0.0-20200819065410-6b70956c85de
14-
github.com/dfinance/glav v0.0.0-20200731202515-8e21f58877c8
14+
github.com/dfinance/glav v0.0.0-20200814081332-c4701f6c12a6
1515
github.com/dfinance/lcs v0.1.7-big
1616
github.com/fsouza/go-dockerclient v1.6.3
1717
github.com/g3co/go-swagger-merger v0.0.0-20200729134821-4edc8debe55f // indirect

helpers/tests/clitester/cli_tester_configs.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/cosmos/cosmos-sdk/server"
1313
sdk "github.com/cosmos/cosmos-sdk/types"
1414
"github.com/cosmos/cosmos-sdk/x/gov"
15+
"github.com/dfinance/glav"
1516

1617
"github.com/dfinance/dnode/cmd/config"
1718
"github.com/dfinance/dnode/x/ccstorage"
@@ -87,11 +88,11 @@ func NewCurrencyMap(cdc *codec.Codec, state GenesisState) map[string]CurrencyInf
8788
for _, params := range ccsGenesis.CurrenciesParams {
8889
info := CurrencyInfo{
8990
Decimals: params.Decimals,
90-
BalancePathHex: params.BalancePathHex,
91-
InfoPathHex: params.InfoPathHex,
91+
BalancePath: glav.BalanceVector(params.Denom),
92+
InfoPath: glav.CurrencyInfoVector(params.Denom),
93+
BalancePathHex: hex.EncodeToString(glav.BalanceVector(params.Denom)),
94+
InfoPathHex: hex.EncodeToString(glav.CurrencyInfoVector(params.Denom)),
9295
}
93-
info.BalancePath, _ = hex.DecodeString(params.BalancePathHex)
94-
info.InfoPath, _ = hex.DecodeString(params.InfoPathHex)
9596

9697
currencies[params.Denom] = info
9798
}

x/ccstorage/client/cli/genesis.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import (
1717
// AddGenesisCurrencyInfo return genesis cmd which adds currency into node genesis state.
1818
func AddGenesisCurrencyInfo(ctx *server.Context, cdc *codec.Codec, defaultNodeHome string) *cobra.Command {
1919
cmd := &cobra.Command{
20-
Use: "set-currency [denom] [decimals] [vmBalancePath] [vmInfoPath]",
20+
Use: "set-currency [denom] [decimals]",
2121
Short: "Set currency to genesis state (non-token)",
22-
Args: cobra.ExactArgs(4),
22+
Args: cobra.ExactArgs(2),
2323
RunE: func(_ *cobra.Command, args []string) error {
2424
// setup viper config
2525
config := ctx.Config
@@ -36,16 +36,6 @@ func AddGenesisCurrencyInfo(ctx *server.Context, cdc *codec.Codec, defaultNodeHo
3636
return err
3737
}
3838

39-
balancePath, _, err := helpers.ParseHexStringParam("vmBalancePath", args[2], helpers.ParamTypeCliArg)
40-
if err != nil {
41-
return err
42-
}
43-
44-
infoPath, _, err := helpers.ParseHexStringParam("vmInfoPath", args[3], helpers.ParamTypeCliArg)
45-
if err != nil {
46-
return err
47-
}
48-
4939
// retrieve the app state
5040
genFile := config.GenesisFile()
5141
appState, genDoc, err := genutil.GenesisStateFromGenFile(cdc, genFile)
@@ -58,10 +48,8 @@ func AddGenesisCurrencyInfo(ctx *server.Context, cdc *codec.Codec, defaultNodeHo
5848

5949
// update the state
6050
params := types.CurrencyParams{
61-
Denom: denom,
62-
Decimals: decimals,
63-
BalancePathHex: balancePath,
64-
InfoPathHex: infoPath,
51+
Denom: denom,
52+
Decimals: decimals,
6553
}
6654
if err := params.Validate(); err != nil {
6755
return fmt.Errorf("invalid params: %w", err)
@@ -97,8 +85,6 @@ func AddGenesisCurrencyInfo(ctx *server.Context, cdc *codec.Codec, defaultNodeHo
9785
helpers.BuildCmdHelp(cmd, []string{
9886
"currency denomination symbol",
9987
"currency decimals count",
100-
"DVM account balance path",
101-
"DVM CurrencyInfo path",
10288
})
10389

10490
return cmd

x/ccstorage/internal/keeper/currency.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ func (k Keeper) CreateCurrency(ctx sdk.Context, params types.CurrencyParams) err
2424
return sdkErrors.Wrapf(types.ErrWrongParams, "currency %q: %v", denom, err)
2525
}
2626

27-
// store VM path objects
28-
k.storeCurrencyBalancePath(ctx, denom, currency.BalancePath())
29-
k.storeCurrencyInfoPath(ctx, denom, currency.InfoPath())
30-
3127
// store currency objects
3228
k.storeCurrency(ctx, currency)
3329
k.storeResStdCurrencyInfo(ctx, currency)

x/ccstorage/internal/keeper/currency_test.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
sdk "github.com/cosmos/cosmos-sdk/types"
9+
"github.com/dfinance/glav"
910
"github.com/stretchr/testify/require"
1011

1112
"github.com/dfinance/dnode/x/ccstorage/internal/types"
@@ -20,10 +21,8 @@ func TestCCSKeeper_CreateCurrency(t *testing.T) {
2021
ctx, keeper := input.ctx, input.keeper
2122

2223
params := types.CurrencyParams{
23-
Denom: "test",
24-
Decimals: 8,
25-
BalancePathHex: "010203",
26-
InfoPathHex: "AABBCC",
24+
Denom: "test",
25+
Decimals: 8,
2726
}
2827
denom := params.Denom
2928

@@ -38,8 +37,6 @@ func TestCCSKeeper_CreateCurrency(t *testing.T) {
3837
require.Equal(t, denom, currency.Denom)
3938
require.EqualValues(t, params.Decimals, currency.Decimals)
4039
require.True(t, currency.Supply.IsZero())
41-
require.Equal(t, params.BalancePathHex, currency.BalancePathHex)
42-
require.Equal(t, params.InfoPathHex, currency.InfoPathHex)
4340
require.True(t, keeper.HasCurrency(ctx, denom))
4441

4542
// check currencyInfo
@@ -52,10 +49,8 @@ func TestCCSKeeper_CreateCurrency(t *testing.T) {
5249
require.False(t, curInfo.IsToken)
5350

5451
// check VM paths
55-
curBalancePath, err := keeper.GetCurrencyBalancePath(ctx, denom)
56-
require.NoError(t, err)
57-
curInfoPath, err := keeper.GetCurrencyInfoPath(ctx, denom)
58-
require.NoError(t, err)
52+
curBalancePath := glav.BalanceVector(denom)
53+
curInfoPath := glav.CurrencyInfoVector(denom)
5954

6055
require.EqualValues(t, currency.BalancePath(), curBalancePath)
6156
require.EqualValues(t, currency.InfoPath(), curInfoPath)
@@ -77,10 +72,8 @@ func TestCCSKeeper_GetCurrency(t *testing.T) {
7772

7873
// create currency
7974
params := types.CurrencyParams{
80-
Denom: "test",
81-
Decimals: uint8(8),
82-
BalancePathHex: "010203",
83-
InfoPathHex: "AABBCC",
75+
Denom: "test",
76+
Decimals: uint8(8),
8477
}
8578
denom := params.Denom
8679

@@ -117,10 +110,8 @@ func TestCCSKeeper_Supply(t *testing.T) {
117110
// create currency
118111
curAmount := sdk.ZeroInt()
119112
params := types.CurrencyParams{
120-
Denom: "test",
121-
Decimals: uint8(8),
122-
BalancePathHex: "010203",
123-
InfoPathHex: "AABBCC",
113+
Denom: "test",
114+
Decimals: uint8(8),
124115
}
125116
denom := params.Denom
126117

x/ccstorage/internal/keeper/genesis.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) json.RawMessage {
3232

3333
for _, currency := range k.GetCurrencies(ctx) {
3434
state.CurrenciesParams = append(state.CurrenciesParams, types.CurrencyParams{
35-
Denom: currency.Denom,
36-
Decimals: currency.Decimals,
37-
BalancePathHex: currency.BalancePathHex,
38-
InfoPathHex: currency.InfoPathHex,
35+
Denom: currency.Denom,
36+
Decimals: currency.Decimals,
3937
})
4038
}
4139

0 commit comments

Comments
 (0)