-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #579 from Atralupus/restore-rune-slot
Restore all rune slot related codes
- Loading branch information
Showing
17 changed files
with
606 additions
and
18 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
2 changes: 1 addition & 1 deletion
2
Mimir.MongoDB.Tests/Bson/ItemSlotDocumentTest.JsonSnapshot.verified.txt
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"AvatarAddress":"0000000000000000000000000000000000000000","Object":{"BattleType":"Adventure","Costumes":[],"Equipments":["0468bfd9-7c76-4379-b1bc-10a3da90c584","0c4c772f-70d9-4a0d-b7e6-4cf25ad7f8f9","13164d27-1948-44a9-9bc7-b23a00aacc5f","2d9d4118-0e3b-445e-aa16-8203e50d2523","4da15d1b-503c-4e08-8476-6f405192258c","98c3abdb-17bc-49a0-8f9c-a61f48662dc7","a45c62d6-e612-4a0e-957a-9ecb7ae6f04f"]},"Metadata":{"SchemaVersion":2,"StoredBlockIndex":0}} | ||
{"ItemSlotAddress":"0000000000000000000000000000000000000000","Object":{"BattleType":"Adventure","Costumes":[],"Equipments":["0468bfd9-7c76-4379-b1bc-10a3da90c584","0c4c772f-70d9-4a0d-b7e6-4cf25ad7f8f9","13164d27-1948-44a9-9bc7-b23a00aacc5f","2d9d4118-0e3b-445e-aa16-8203e50d2523","4da15d1b-503c-4e08-8476-6f405192258c","98c3abdb-17bc-49a0-8f9c-a61f48662dc7","a45c62d6-e612-4a0e-957a-9ecb7ae6f04f"]},"Metadata":{"SchemaVersion":2,"StoredBlockIndex":0}} |
1 change: 1 addition & 0 deletions
1
Mimir.MongoDB.Tests/Bson/RuneSlotDocumentTest.JsonSnapshot.verified.txt
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 @@ | ||
{"RuneSlotAddress":"0000000000000000000000000000000000000000","Object":{"BattleType":"Adventure","Slots":[{"Index":0,"RuneSlotType":"Default","RuneType":"Stat","IsLock":false,"RuneId":10012},{"Index":1,"RuneSlotType":"Ncg","RuneType":"Stat","IsLock":true},{"Index":2,"RuneSlotType":"Stake","RuneType":"Stat","IsLock":true},{"Index":3,"RuneSlotType":"Default","RuneType":"Skill","IsLock":false},{"Index":4,"RuneSlotType":"Ncg","RuneType":"Skill","IsLock":true},{"Index":5,"RuneSlotType":"Stake","RuneType":"Skill","IsLock":true},{"Index":6,"RuneSlotType":"Crystal","RuneType":"Stat","IsLock":true},{"Index":7,"RuneSlotType":"Crystal","RuneType":"Skill","IsLock":true}]},"Metadata":{"SchemaVersion":1,"StoredBlockIndex":0}} |
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,20 @@ | ||
using Lib9c.Models.States; | ||
using Mimir.MongoDB.Bson; | ||
using Mimir.MongoDB.Tests.TestDatas; | ||
|
||
namespace Mimir.MongoDB.Tests.Bson; | ||
|
||
public class RuneSlotDocumentTest | ||
{ | ||
[Fact] | ||
public Task JsonSnapshot() | ||
{ | ||
var docs = new RuneSlotDocument( | ||
default, | ||
default, | ||
default, | ||
new RuneSlotState(TestDataHelpers.LoadState("RuneSlotState.bin")) | ||
); | ||
return Verify(docs.ToJson()); | ||
} | ||
} |
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,14 @@ | ||
using Lib9c.Models.States; | ||
using Libplanet.Crypto; | ||
using MongoDB.Bson.Serialization.Attributes; | ||
using Newtonsoft.Json; | ||
|
||
namespace Mimir.MongoDB.Bson; | ||
|
||
[BsonIgnoreExtraElements] | ||
public record RuneSlotDocument( | ||
[property: BsonIgnore, JsonIgnore] long StoredBlockIndex, | ||
[property: BsonIgnore, JsonIgnore] Address AvatarAddress, | ||
Address RuneSlotAddress, | ||
RuneSlotState Object | ||
) : MimirBsonDocument(AvatarAddress.ToHex(), new DocumentMetadata(1, StoredBlockIndex)); |
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,40 @@ | ||
using Libplanet.Crypto; | ||
using Mimir.MongoDB.Bson; | ||
using Mimir.MongoDB.Exceptions; | ||
using Mimir.MongoDB.Services; | ||
using MongoDB.Driver; | ||
using Nekoyume.Model.EnumType; | ||
|
||
namespace Mimir.MongoDB.Repositories; | ||
|
||
public interface IRuneSlotRepository | ||
{ | ||
Task<RuneSlotDocument> GetByAddressAsync(Address avatarAddress, BattleType battleType); | ||
} | ||
|
||
public class RuneSlotRepository(MongoDbService dbService) : IRuneSlotRepository | ||
{ | ||
public async Task<RuneSlotDocument> GetByAddressAsync( | ||
Address avatarAddress, | ||
BattleType battleType | ||
) | ||
{ | ||
var runeSlotAddress = Nekoyume.Model.State.RuneSlotState.DeriveAddress( | ||
avatarAddress, | ||
battleType | ||
); | ||
var collectionName = CollectionNames.GetCollectionName<RuneSlotDocument>(); | ||
var collection = dbService.GetCollection<RuneSlotDocument>(collectionName); | ||
var filter = Builders<RuneSlotDocument>.Filter.Eq("_id", runeSlotAddress.ToHex()); | ||
var document = await collection.Find(filter).FirstOrDefaultAsync(); | ||
if (document is null) | ||
{ | ||
throw new DocumentNotFoundInMongoCollectionException( | ||
collection.CollectionNamespace.CollectionName, | ||
$"'Address' equals to '{runeSlotAddress.ToHex()}'" | ||
); | ||
} | ||
|
||
return document; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Mimir.Tests/QueryTests/RuneSlotTest.GraphQL_Query_RuneSlot_Returns_CorrectValue.verified.txt
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,16 @@ | ||
{ | ||
"data": { | ||
"runeSlot": { | ||
"battleType": "ADVENTURE", | ||
"slots": [ | ||
{ | ||
"index": 1, | ||
"runeSlotType": "DEFAULT", | ||
"runeType": "STAT", | ||
"isLock": false, | ||
"runeId": 10 | ||
} | ||
] | ||
} | ||
} | ||
} |
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,63 @@ | ||
using Lib9c.Models.Runes; | ||
using Lib9c.Models.States; | ||
using Libplanet.Crypto; | ||
using Mimir.MongoDB.Bson; | ||
using Mimir.MongoDB.Repositories; | ||
using Moq; | ||
|
||
namespace Mimir.Tests.QueryTests; | ||
|
||
public class RuneSlotTest | ||
{ | ||
[Fact] | ||
public async Task GraphQL_Query_RuneSlot_Returns_CorrectValue() | ||
{ | ||
var address = new Address("0x0000000001000000000200000000030000000004"); | ||
var state = new RuneSlotState | ||
{ | ||
BattleType = Nekoyume.Model.EnumType.BattleType.Adventure, | ||
Slots = new List<RuneSlot> | ||
{ | ||
new RuneSlot | ||
{ | ||
Index = 1, | ||
RuneSlotType = Nekoyume.Model.EnumType.RuneSlotType.Default, | ||
RuneType = Nekoyume.Model.EnumType.RuneType.Stat, | ||
IsLock = false, | ||
RuneId = 10 | ||
} | ||
}, | ||
}; | ||
var mockRepo = new Mock<IRuneSlotRepository>(); | ||
mockRepo | ||
.Setup(repo => | ||
repo.GetByAddressAsync( | ||
It.IsAny<Address>(), | ||
Nekoyume.Model.EnumType.BattleType.Adventure | ||
) | ||
) | ||
.ReturnsAsync(new RuneSlotDocument(1, address, address, state)); | ||
var serviceProvider = TestServices.Builder.With(mockRepo.Object).Build(); | ||
var query = $$""" | ||
query { | ||
runeSlot(address: "{{address}}", battleType: ADVENTURE) { | ||
battleType, | ||
slots { | ||
index | ||
runeSlotType | ||
runeType | ||
isLock | ||
runeId | ||
} | ||
} | ||
} | ||
"""; | ||
|
||
var result = await TestServices.ExecuteRequestAsync( | ||
serviceProvider, | ||
b => b.SetDocument(query) | ||
); | ||
|
||
await Verify(result); | ||
} | ||
} |
Oops, something went wrong.