-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
812 additions
and
27 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
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
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
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
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,34 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types" | ||
) | ||
|
||
func (k Keeper) GetSynchronyParams(ctx sdk.Context) types.SynchronyParams { | ||
store := ctx.KVStore(k.storeKey) | ||
bytes := store.Get([]byte(types.SynchronyParamsKey)) | ||
|
||
if bytes == nil { | ||
fmt.Printf("!! Returning default synchrony params\n") | ||
return types.DefaultSynchronyParams() | ||
} | ||
|
||
var params types.SynchronyParams | ||
k.cdc.MustUnmarshal(bytes, ¶ms) | ||
fmt.Printf("Returning un-nil synchrony params: %v\n", params) | ||
return params | ||
} | ||
|
||
func (k Keeper) SetSynchronyParams(ctx sdk.Context, params types.SynchronyParams) { | ||
store := ctx.KVStore(k.storeKey) | ||
store.Set([]byte(types.SynchronyParamsKey), k.cdc.MustMarshal(¶ms)) | ||
} | ||
|
||
func (k Keeper) GetBlockDelay(ctx sdk.Context) time.Duration { | ||
return k.GetSynchronyParams(ctx).NextBlockDelay | ||
} |
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,49 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/blocktime/keeper" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_Set_GetSynchronyParams_GetBlockDelay(t *testing.T) { | ||
tests := map[string]struct { | ||
setUp func(keeper.Keeper, sdk.Context) | ||
expectedSynchronyParams types.SynchronyParams | ||
expectedBlockDelay time.Duration | ||
}{ | ||
"No set-up, empty synchrony params, block_delay = 0": { | ||
setUp: func(k keeper.Keeper, ctx sdk.Context) { | ||
}, | ||
expectedSynchronyParams: types.DefaultSynchronyParams(), | ||
expectedBlockDelay: 0, | ||
}, | ||
"Non-nil synchrony param": { | ||
setUp: func(k keeper.Keeper, ctx sdk.Context) { | ||
k.SetSynchronyParams(ctx, types.SynchronyParams{ | ||
NextBlockDelay: 300 * time.Millisecond, | ||
}) | ||
}, | ||
expectedSynchronyParams: types.SynchronyParams{ | ||
NextBlockDelay: 300 * time.Millisecond, | ||
}, | ||
expectedBlockDelay: 300 * time.Millisecond, | ||
}, | ||
} | ||
|
||
for name, tc := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
tApp := testapp.NewTestAppBuilder(t).Build() | ||
ctx := tApp.InitChain() | ||
k := tApp.App.BlockTimeKeeper | ||
tc.setUp(k, ctx) | ||
require.Equal(t, tc.expectedSynchronyParams, k.GetSynchronyParams(ctx)) | ||
require.Equal(t, tc.expectedBlockDelay, k.GetBlockDelay(ctx)) | ||
}) | ||
} | ||
} |
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
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
Oops, something went wrong.