github.com/KiraCore/sekai@v0.3.43/x/layer2/keeper/dapp_session_test.go (about) 1 package keeper_test 2 3 import ( 4 "github.com/KiraCore/sekai/x/layer2/types" 5 ) 6 7 func (suite *KeeperTestSuite) TestDappSessionSetGetDelete() { 8 registrars := []types.ExecutionRegistrar{ 9 { 10 DappName: "dapp1", 11 PrevSession: nil, 12 CurrSession: nil, 13 NextSession: nil, 14 }, 15 { 16 DappName: "dapp2", 17 PrevSession: nil, 18 CurrSession: nil, 19 NextSession: &types.DappSession{ 20 Leader: "kira1q24436yrnettd6v4eu6r4t9gycnnddack4jr5r", 21 Start: 1680141605, 22 StatusHash: "0c", 23 Status: types.SessionUnscheduled, 24 Gateway: "dapp2.com", 25 }, 26 }, 27 { 28 DappName: "dapp3", 29 PrevSession: nil, 30 CurrSession: &types.DappSession{ 31 Leader: "kira1q24436yrnettd6v4eu6r4t9gycnnddack4jr5r", 32 Start: 1680141605, 33 StatusHash: "0c", 34 Status: types.SessionOngoing, 35 Gateway: "dapp3.com", 36 }, 37 NextSession: &types.DappSession{ 38 Leader: "kira1q24436yrnettd6v4eu6r4t9gycnnddack4jr5r", 39 Start: 1680141605, 40 StatusHash: "0c", 41 Status: types.SessionUnscheduled, 42 Gateway: "dapp3.com", 43 }, 44 }, 45 { 46 DappName: "dapp4", 47 PrevSession: &types.DappSession{ 48 Leader: "kira1q24436yrnettd6v4eu6r4t9gycnnddack4jr5r", 49 Start: 1680141605, 50 StatusHash: "0c", 51 Status: types.SessionAccepted, 52 Gateway: "dapp4.com", 53 }, 54 CurrSession: &types.DappSession{ 55 Leader: "kira1q24436yrnettd6v4eu6r4t9gycnnddack4jr5r", 56 Start: 1680141605, 57 StatusHash: "0c", 58 Status: types.SessionOngoing, 59 Gateway: "dapp4.com", 60 }, 61 NextSession: &types.DappSession{ 62 Leader: "kira1q24436yrnettd6v4eu6r4t9gycnnddack4jr5r", 63 Start: 1680141605, 64 StatusHash: "0c", 65 Status: types.SessionUnscheduled, 66 Gateway: "dapp4.com", 67 }, 68 }, 69 } 70 71 for _, registrar := range registrars { 72 suite.app.Layer2Keeper.SetDappSession(suite.ctx, registrar) 73 } 74 75 for _, registrar := range registrars { 76 c := suite.app.Layer2Keeper.GetDappSession(suite.ctx, registrar.DappName) 77 suite.Require().Equal(c, registrar) 78 } 79 80 allRegistrars := suite.app.Layer2Keeper.GetAllDappSessions(suite.ctx) 81 suite.Require().Len(allRegistrars, 4) 82 83 suite.app.Layer2Keeper.DeleteDappSession(suite.ctx, registrars[0].DappName) 84 85 registrar := suite.app.Layer2Keeper.GetDappSession(suite.ctx, registrars[0].DappName) 86 suite.Require().Equal(registrar.DappName, "") 87 88 allRegistrars = suite.app.Layer2Keeper.GetAllDappSessions(suite.ctx) 89 suite.Require().Len(allRegistrars, 3) 90 } 91 92 // TODO: add test for ResetNewSession 93 // TODO: add test for CreateNewSession