-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testing harness for e2e application logic tests (#850)
* Add testing harness for e2e go tests * polish * add mint/epoch/distribution tests/helpers * dex test * refactor * rebase
- Loading branch information
Showing
25 changed files
with
1,442 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/x/auth/signing" | ||
"github.com/sei-protocol/sei-chain/testutil/processblock" | ||
"github.com/sei-protocol/sei-chain/testutil/processblock/verify" | ||
) | ||
|
||
func TestPlaceOrders(t *testing.T) { | ||
app := processblock.NewTestApp() | ||
p := processblock.DexPreset(app, 3, 2) | ||
p.DoRegisterMarkets(app) | ||
|
||
for _, testCase := range []TestCase{ | ||
{ | ||
description: "send a single market buy without counterparty on orderbook", | ||
input: []signing.Tx{ | ||
app.Sign(p.SignableAccounts[0], 10000, p.AllDexMarkets[0].LongMarketOrder(p.SignableAccounts[0], "11", "2")), | ||
}, | ||
verifier: []verify.Verifier{ | ||
verify.DexOrders, | ||
}, | ||
expectedCodes: []uint32{0}, | ||
}, | ||
{ | ||
description: "send a single market sell without counterparty on orderbook", | ||
input: []signing.Tx{ | ||
app.Sign(p.SignableAccounts[0], 10000, p.AllDexMarkets[0].ShortMarketOrder(p.SignableAccounts[0], "10.5", "4")), | ||
}, | ||
verifier: []verify.Verifier{ | ||
verify.DexOrders, | ||
}, | ||
expectedCodes: []uint32{0}, | ||
}, | ||
{ | ||
description: "send a single buy limit order", | ||
input: []signing.Tx{ | ||
app.Sign(p.SignableAccounts[0], 10000, p.AllDexMarkets[0].LongLimitOrder(p.SignableAccounts[0], "10.5", "5")), | ||
}, | ||
verifier: []verify.Verifier{ | ||
verify.DexOrders, | ||
}, | ||
expectedCodes: []uint32{0}, | ||
}, | ||
{ | ||
description: "send a single sell limit order", | ||
input: []signing.Tx{ | ||
app.Sign(p.SignableAccounts[1], 10000, p.AllDexMarkets[0].ShortLimitOrder(p.SignableAccounts[1], "11", "3")), | ||
}, | ||
verifier: []verify.Verifier{ | ||
verify.DexOrders, | ||
}, | ||
expectedCodes: []uint32{0}, | ||
}, | ||
{ | ||
description: "send a single market buy without exhausting the orderbook", | ||
input: []signing.Tx{ | ||
app.Sign(p.SignableAccounts[2], 10000, p.AllDexMarkets[0].LongMarketOrder(p.SignableAccounts[2], "11", "2")), | ||
}, | ||
verifier: []verify.Verifier{ | ||
verify.DexOrders, | ||
}, | ||
expectedCodes: []uint32{0}, | ||
}, | ||
{ | ||
description: "send a single market sell without exhausting the orderbook", | ||
input: []signing.Tx{ | ||
app.Sign(p.SignableAccounts[2], 10000, p.AllDexMarkets[0].ShortMarketOrder(p.SignableAccounts[2], "10.5", "4")), | ||
}, | ||
verifier: []verify.Verifier{ | ||
verify.DexOrders, | ||
}, | ||
expectedCodes: []uint32{0}, | ||
}, | ||
{ | ||
description: "send a single market buy exhausting the orderbook", | ||
input: []signing.Tx{ | ||
app.Sign(p.SignableAccounts[2], 10000, p.AllDexMarkets[0].LongMarketOrder(p.SignableAccounts[2], "12", "2")), | ||
}, | ||
verifier: []verify.Verifier{ | ||
verify.DexOrders, | ||
}, | ||
expectedCodes: []uint32{0}, | ||
}, | ||
{ | ||
description: "send a single market sell exhausting the orderbook", | ||
input: []signing.Tx{ | ||
app.Sign(p.SignableAccounts[2], 10000, p.AllDexMarkets[0].ShortMarketOrder(p.SignableAccounts[2], "10", "2")), | ||
}, | ||
verifier: []verify.Verifier{ | ||
verify.DexOrders, | ||
}, | ||
expectedCodes: []uint32{0}, | ||
}, | ||
} { | ||
testCase.run(t, app) | ||
} | ||
} |
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,35 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/x/auth/signing" | ||
"github.com/sei-protocol/sei-chain/testutil/processblock" | ||
"github.com/sei-protocol/sei-chain/testutil/processblock/msgs" | ||
"github.com/sei-protocol/sei-chain/testutil/processblock/verify" | ||
) | ||
|
||
func TestDistribution(t *testing.T) { | ||
app := processblock.NewTestApp() | ||
p := processblock.CommonPreset(app) | ||
for _, testCase := range []TestCase{ | ||
{ | ||
description: "send to accrue fee for next block", | ||
input: []signing.Tx{ | ||
p.AdminSign(app, msgs.Send(p.Admin, p.AllAccounts[0], 1000)), | ||
}, | ||
verifier: []verify.Verifier{}, | ||
expectedCodes: []uint32{0}, | ||
}, | ||
{ | ||
description: "check distribution", | ||
input: []signing.Tx{}, | ||
verifier: []verify.Verifier{ | ||
verify.Allocation, | ||
}, | ||
expectedCodes: []uint32{}, | ||
}, | ||
} { | ||
testCase.run(t, app) | ||
} | ||
} |
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,39 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/cosmos/cosmos-sdk/x/auth/signing" | ||
"github.com/sei-protocol/sei-chain/testutil/processblock" | ||
"github.com/sei-protocol/sei-chain/testutil/processblock/verify" | ||
) | ||
|
||
func TestEpoch(t *testing.T) { | ||
app := processblock.NewTestApp() | ||
_ = processblock.CommonPreset(app) | ||
app.FastEpoch() | ||
for i, testCase := range []TestCase{ | ||
{ | ||
description: "first epoch", | ||
input: []signing.Tx{}, | ||
verifier: []verify.Verifier{ | ||
verify.Epoch, | ||
}, | ||
expectedCodes: []uint32{}, | ||
}, | ||
{ | ||
description: "second epoch", | ||
input: []signing.Tx{}, | ||
verifier: []verify.Verifier{ | ||
verify.Epoch, | ||
}, | ||
expectedCodes: []uint32{}, | ||
}, | ||
} { | ||
if i > 0 { | ||
time.Sleep(6 * time.Second) | ||
} | ||
testCase.run(t, app) | ||
} | ||
} |
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,40 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/cosmos/cosmos-sdk/x/auth/signing" | ||
"github.com/sei-protocol/sei-chain/testutil/processblock" | ||
"github.com/sei-protocol/sei-chain/testutil/processblock/verify" | ||
) | ||
|
||
func TestMint(t *testing.T) { | ||
app := processblock.NewTestApp() | ||
_ = processblock.CommonPreset(app) | ||
app.NewMinter(1000000) | ||
app.FastEpoch() | ||
for i, testCase := range []TestCase{ | ||
{ | ||
description: "first epoch", | ||
input: []signing.Tx{}, | ||
verifier: []verify.Verifier{ | ||
verify.MintRelease, | ||
}, | ||
expectedCodes: []uint32{}, | ||
}, | ||
{ | ||
description: "second epoch", | ||
input: []signing.Tx{}, | ||
verifier: []verify.Verifier{ | ||
verify.MintRelease, | ||
}, | ||
expectedCodes: []uint32{}, | ||
}, | ||
} { | ||
if i > 0 { | ||
time.Sleep(6 * time.Second) | ||
} | ||
testCase.run(t, app) | ||
} | ||
} |
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,56 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/x/auth/signing" | ||
"github.com/sei-protocol/sei-chain/testutil/processblock" | ||
"github.com/sei-protocol/sei-chain/testutil/processblock/msgs" | ||
"github.com/sei-protocol/sei-chain/testutil/processblock/verify" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type TestCase struct { | ||
description string | ||
input []signing.Tx | ||
verifier []verify.Verifier | ||
expectedCodes []uint32 | ||
} | ||
|
||
func (c *TestCase) run(t *testing.T, app *processblock.App) { | ||
blockRunner := func() []uint32 { return app.RunBlock(c.input) } | ||
for _, v := range c.verifier { | ||
blockRunner = v(t, app, blockRunner, c.input) | ||
} | ||
require.Equal(t, c.expectedCodes, blockRunner(), c.description) | ||
} | ||
|
||
func TestTemplate(t *testing.T) { | ||
app := processblock.NewTestApp() | ||
p := processblock.CommonPreset(app) // choose a preset | ||
for _, testCase := range []TestCase{ | ||
{ | ||
description: "simple send 1", | ||
input: []signing.Tx{ | ||
p.AdminSign(app, msgs.Send(p.Admin, p.AllAccounts[0], 1000)), | ||
}, | ||
verifier: []verify.Verifier{ | ||
verify.Balance, | ||
}, | ||
expectedCodes: []uint32{0}, | ||
}, | ||
{ | ||
description: "simple send 2", | ||
input: []signing.Tx{ | ||
p.AdminSign(app, msgs.Send(p.Admin, p.AllAccounts[1], 2000)), | ||
p.AdminSign(app, msgs.Send(p.Admin, p.AllAccounts[2], 3000)), | ||
}, | ||
verifier: []verify.Verifier{ | ||
verify.Balance, | ||
}, | ||
expectedCodes: []uint32{0, 0}, | ||
}, | ||
} { | ||
testCase.run(t, app) | ||
} | ||
} |
Oops, something went wrong.