Skip to content

Commit

Permalink
update: test page
Browse files Browse the repository at this point in the history
  • Loading branch information
TiyoSheng committed Oct 25, 2023
1 parent 7943fcf commit 0b60ef1
Show file tree
Hide file tree
Showing 471 changed files with 86 additions and 3,048,011 deletions.
2 changes: 1 addition & 1 deletion packages/client/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VITE_CHAIN_ID=4242
VITE_CHAIN_ID=31337
4 changes: 2 additions & 2 deletions packages/client/src/mud/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export function createSystemCalls(
}

const getBattlePlayerHp = async (battleId: any, addr: any) => {
const tx = await worldContract.write.getBattlePlayerHp([battleId, addr]);
await waitForTransaction(tx);
const data = await worldContract.read.getBattlePlayerHp([battleId, addr]);
return data
}
return {
increment,
Expand Down
24 changes: 17 additions & 7 deletions packages/client/src/pages/test/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { getRandomStr } from '../../utils/utils';
import './index.scss';

const abi = [{"inputs":[{"internalType":"uint256","name":"_waitBlockCount","type":"uint256"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_notRevealedInfo","type":"string"},{"internalType":"string","name":"_revealedDesc","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"randomId","type":"uint256"},{"indexed":false,"internalType":"address","name":"author","type":"address"}],"name":"NewRandom","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"randomId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"randomList","outputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"},{"internalType":"address","name":"author","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"revealNFT","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"userList","outputs":[{"internalType":"uint256","name":"randomId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"HP","type":"uint256"},{"internalType":"uint256","name":"Attack","type":"uint256"},{"internalType":"uint256","name":"AttackRange","type":"uint256"},{"internalType":"uint256","name":"Speed","type":"uint256"},{"internalType":"uint256","name":"Strength","type":"uint256"},{"internalType":"uint256","name":"Space","type":"uint256"},{"internalType":"enum MRandom.RandomState","name":"state","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"waitBlockCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
const contractAddress = '0x5FbDB2315678afecb367f032d93F642f64180aa3'
const rpc = 'http://127.0.0.1:8545'

const Test = () => {
const [stepData, setStepData] = useState([]);
Expand All @@ -24,7 +26,7 @@ const Test = () => {

const {
components: { Player, GameConfig, BattleList, BoxList, GlobalConfig },
systemCalls: { move, joinBattlefield, transfer, battleInvitation, confirmBattle, selectUserNft, revealBattle, openBox, revealBox, getCollections, CreateBox },
systemCalls: { move, joinBattlefield, transfer, battleInvitation, confirmBattle, selectUserNft, revealBattle, openBox, revealBox, getCollections, CreateBox, getBattlePlayerHp },
network
} = useMUD();

Expand Down Expand Up @@ -58,9 +60,9 @@ const Test = () => {
return battle;
});
console.log(battles, 'battles')
battles.forEach(item => {
battles.forEach(async item => {
if (item.attackerState == 2 && item.defenderState == 2) {
let hp = getBattlePlayerHp(item.id, account)
let hp = await getBattlePlayerHp(item.id, account)
console.log(hp, 'hp')
}
})
Expand Down Expand Up @@ -97,24 +99,27 @@ const Test = () => {

const mintFun = () => {
let privateKey = network.privateKey
let provider = new ethers.providers.JsonRpcProvider('https://follower.testnet-chain.linfra.xyz')
let provider = new ethers.providers.JsonRpcProvider(rpc)
let wallet = new ethers.Wallet(privateKey, provider)
console.log(wallet)
let userContractAddress = '0x685c65e0c699EC5E52877D2E133d87103d5fa393'
let userContractAddress = contractAddress
let userContract = new ethers.Contract(userContractAddress, abi, wallet)
console.log(userContract)
userContract.mint().then(async res => {
console.log(res, 'res')
await res.wait()
userContract.tokenId().then(res => {
console.log(res, 'tokenId')
})
})
}

const revealNFTFun = () => {
let privateKey = network.privateKey
let provider = new ethers.providers.JsonRpcProvider('https://follower.testnet-chain.linfra.xyz')
let provider = new ethers.providers.JsonRpcProvider(rpc)
let wallet = new ethers.Wallet(privateKey, provider)
console.log(wallet)
let userContractAddress = '0x685c65e0c699EC5E52877D2E133d87103d5fa393'
let userContractAddress = contractAddress
let userContract = new ethers.Contract(userContractAddress, abi, wallet)
userContract.revealNFT(revealNFTData).then(async res => {
console.log(res)
Expand Down Expand Up @@ -241,6 +246,11 @@ const Test = () => {
let bettleItem = battlesData.filter(item => item.id == battle.id)[0]
console.log(bettleItem, 'bettleItem')
revealBattle(battle.id, bettleItem.action, bettleItem.arg, bettleItem.nonce);
// 删除bettleItem
let battlesDataTemp = [...battlesData];
let index = battlesDataTemp.findIndex(item => item.id == battle.id);
battlesDataTemp.splice(index, 1);
setBattlesData(battlesDataTemp)
}

const CreateBoxFun = () => {
Expand Down
File renamed without changes.

This file was deleted.

Loading

0 comments on commit 0b60ef1

Please sign in to comment.