Skip to content

Commit de87ace

Browse files
authored
Merge pull request #266 from cosmos/feature/iavl-app
Refactor out BaseApp, StoreApp (per spec #1 and #2)
2 parents 6c667b8 + acdc083 commit de87ace

File tree

24 files changed

+845
-629
lines changed

24 files changed

+845
-629
lines changed

app/app.go

Lines changed: 0 additions & 240 deletions
This file was deleted.

app/app_test.go

Lines changed: 28 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func DefaultHandler(feeDenom string) sdk.Handler {
5555
type appTest struct {
5656
t *testing.T
5757
chainID string
58-
app *Basecoin
58+
app *BaseApp
5959
acctIn *coin.AccountWithKey
6060
acctOut *coin.AccountWithKey
6161
}
@@ -100,8 +100,8 @@ func (at *appTest) feeTx(coins coin.Coins, toll coin.Coin, sequence uint32) sdk.
100100

101101
// set the account on the app through InitState
102102
func (at *appTest) initAccount(acct *coin.AccountWithKey) {
103-
res := at.app.InitState("coin/account", acct.MakeOption())
104-
require.EqualValues(at.t, res, "Success")
103+
err := at.app.InitState("coin", "account", acct.MakeOption())
104+
require.Nil(at.t, err, "%+v", err)
105105
}
106106

107107
// reset the in and out accs to be one account each with 7mycoin
@@ -112,17 +112,13 @@ func (at *appTest) reset() {
112112
// Note: switch logger if you want to get more info
113113
logger := log.TestingLogger()
114114
// logger := log.NewTracingLogger(log.NewTMLogger(os.Stdout))
115-
store, err := NewStore("", 0, logger.With("module", "store"))
116-
require.Nil(at.t, err, "%+v", err)
117115

118-
at.app = NewBasecoin(
119-
DefaultHandler("mycoin"),
120-
store,
121-
logger.With("module", "app"),
122-
)
116+
store, err := NewStoreApp("app-test", "", 0, logger)
117+
require.Nil(at.t, err, "%+v", err)
118+
at.app = NewBaseApp(store, DefaultHandler("mycoin"), nil)
123119

124-
res := at.app.InitState("base/chain_id", at.chainID)
125-
require.EqualValues(at.t, res, "Success")
120+
err = at.app.InitState("base", "chain_id", at.chainID)
121+
require.Nil(at.t, err, "%+v", err)
126122

127123
at.initAccount(at.acctIn)
128124
at.initAccount(at.acctOut)
@@ -146,9 +142,9 @@ func getAddr(addr []byte, state state.SimpleDB) (coin.Coins, error) {
146142
func (at *appTest) exec(t *testing.T, tx sdk.Tx, checkTx bool) (res abci.Result, diffIn, diffOut coin.Coins) {
147143
require := require.New(t)
148144

149-
initBalIn, err := getBalance(at.acctIn.Actor(), at.app.GetState())
145+
initBalIn, err := getBalance(at.acctIn.Actor(), at.app.Append())
150146
require.Nil(err, "%+v", err)
151-
initBalOut, err := getBalance(at.acctOut.Actor(), at.app.GetState())
147+
initBalOut, err := getBalance(at.acctOut.Actor(), at.app.Append())
152148
require.Nil(err, "%+v", err)
153149

154150
txBytes := wire.BinaryBytes(tx)
@@ -158,9 +154,9 @@ func (at *appTest) exec(t *testing.T, tx sdk.Tx, checkTx bool) (res abci.Result,
158154
res = at.app.DeliverTx(txBytes)
159155
}
160156

161-
endBalIn, err := getBalance(at.acctIn.Actor(), at.app.GetState())
157+
endBalIn, err := getBalance(at.acctIn.Actor(), at.app.Append())
162158
require.Nil(err, "%+v", err)
163-
endBalOut, err := getBalance(at.acctOut.Actor(), at.app.GetState())
159+
endBalOut, err := getBalance(at.acctOut.Actor(), at.app.Append())
164160
require.Nil(err, "%+v", err)
165161
return res, endBalIn.Minus(initBalIn), endBalOut.Minus(initBalOut)
166162
}
@@ -172,29 +168,24 @@ func TestInitState(t *testing.T) {
172168
require := require.New(t)
173169

174170
logger := log.TestingLogger()
175-
store, err := NewStore("", 0, logger.With("module", "store"))
171+
store, err := NewStoreApp("app-test", "", 0, logger)
176172
require.Nil(err, "%+v", err)
177-
178-
app := NewBasecoin(
179-
DefaultHandler("atom"),
180-
store,
181-
logger.With("module", "app"),
182-
)
173+
app := NewBaseApp(store, DefaultHandler("atom"), nil)
183174

184175
//testing ChainID
185176
chainID := "testChain"
186-
res := app.InitState("base/chain_id", chainID)
177+
err = app.InitState("base", "chain_id", chainID)
178+
require.Nil(err, "%+v", err)
187179
assert.EqualValues(app.GetChainID(), chainID)
188-
assert.EqualValues(res, "Success")
189180

190181
// make a nice account...
191182
bal := coin.Coins{{"atom", 77}, {"eth", 12}}
192183
acct := coin.NewAccountWithKey(bal)
193-
res = app.InitState("coin/account", acct.MakeOption())
194-
require.EqualValues(res, "Success")
184+
err = app.InitState("coin", "account", acct.MakeOption())
185+
require.Nil(err, "%+v", err)
195186

196187
// make sure it is set correctly, with some balance
197-
coins, err := getBalance(acct.Actor(), app.GetState())
188+
coins, err := getBalance(acct.Actor(), app.Append())
198189
require.Nil(err)
199190
assert.Equal(bal, coins)
200191

@@ -218,23 +209,22 @@ func TestInitState(t *testing.T) {
218209
}
219210
]
220211
}`
221-
res = app.InitState("coin/account", unsortAcc)
222-
require.EqualValues(res, "Success")
212+
err = app.InitState("coin", "account", unsortAcc)
213+
require.Nil(err, "%+v", err)
223214

224-
coins, err = getAddr(unsortAddr, app.GetState())
215+
coins, err = getAddr(unsortAddr, app.Append())
225216
require.Nil(err)
226217
assert.True(coins.IsValid())
227218
assert.Equal(unsortCoins, coins)
228219

229-
res = app.InitState("base/dslfkgjdas", "")
230-
assert.NotEqual(res, "Success")
220+
err = app.InitState("base", "dslfkgjdas", "")
221+
require.NotNil(err)
231222

232-
res = app.InitState("dslfkgjdas", "")
233-
assert.NotEqual(res, "Success")
234-
235-
res = app.InitState("dslfkgjdas/szfdjzs", "")
236-
assert.NotEqual(res, "Success")
223+
err = app.InitState("", "dslfkgjdas", "")
224+
require.NotNil(err)
237225

226+
err = app.InitState("dslfkgjdas", "szfdjzs", "")
227+
require.NotNil(err)
238228
}
239229

240230
// Test CheckTx and DeliverTx with insufficient and sufficient balance
@@ -301,19 +291,3 @@ func TestQuery(t *testing.T) {
301291
})
302292
assert.NotEqual(resQueryPreCommit, resQueryPostCommit, "Query should change before/after commit")
303293
}
304-
305-
func TestSplitKey(t *testing.T) {
306-
assert := assert.New(t)
307-
prefix, suffix := splitKey("foo/bar")
308-
assert.EqualValues("foo", prefix)
309-
assert.EqualValues("bar", suffix)
310-
311-
prefix, suffix = splitKey("foobar")
312-
assert.EqualValues("base", prefix)
313-
assert.EqualValues("foobar", suffix)
314-
315-
prefix, suffix = splitKey("some/complex/issue")
316-
assert.EqualValues("some", prefix)
317-
assert.EqualValues("complex/issue", suffix)
318-
319-
}

0 commit comments

Comments
 (0)