Skip to content

Commit

Permalink
Added custom messages for mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
maxpetretta committed Jul 8, 2022
1 parent c56d5de commit ee6b2d0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
14 changes: 10 additions & 4 deletions hardhat/scripts/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const main = async () => {
const network = hre.network.name
const options = { value: hre.ethers.utils.parseEther("0.001") }

const messages = ["gm", "Hello Twitt3r!", "Wen merge", "web3 is so cool!", "Ethereum is the future", "Who's in NYC?", "How is this website free 😂", "Alright, time for a thread 🧵:"]
const replies = ["gm", "This is the way", "To the moon!", "iAintReadingAllThat.jpg", "Brutal", "Let's goooo", "Soon™️", "DM me", "Rugged again 😭", "🔥", "🫡"]

// Exit early if not on localhost
if (network != "localhost") {
console.log("Mock script can only be ran on localhost!")
Expand All @@ -20,6 +23,9 @@ const main = async () => {
console.log("Deploying contract with account:", owner.address)
console.log("Account balance:", hre.ethers.utils.formatEther(balance))

console.log("\nDeploying in 5 seconds...")
await sleep(5000)

const contract = await hre.ethers.getContractFactory("Twitt3r")
const twitt3r = await contract.deploy(
0, // Odds
Expand All @@ -44,11 +50,11 @@ const main = async () => {

switch(rng(0, 3)) {
case 0: // Top-level tweet
txn = await twitt3r.connect(account).newTweet("Tweet", 0, 0, options)
txn = await twitt3r.connect(account).newTweet(messages[rng(0, messages.length)], 0, 0, options)
await txn.wait()
break
case 1: // Reply tweet
txn = await twitt3r.connect(account).newTweet("Reply", rng(1, id + 1), 0, options)
txn = await twitt3r.connect(account).newTweet(replies[rng(0, replies.length)], rng(1, id + 1), 0, options)
await txn.wait()
break
case 2: // Retweet
Expand Down Expand Up @@ -82,8 +88,8 @@ const main = async () => {
const count = await twitt3r.getTotalTweets()
console.log("Total tweets sent:", count.toNumber())

// const tweets = await twitt3r.getTweets()
// console.log("\n----- Sent Tweets -----\n", tweets)
const tweets = await twitt3r.getTweets()
console.log("\n----- Sent Tweets -----\n", tweets)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion react/components/Avatar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function Avatar(props) {
"bg-sky-400",
"bg-indigo-400",
"bg-purple-400",
"bg-fushsia-400",
"bg-fuchsia-400",
"bg-rose-400",
]

Expand Down
30 changes: 15 additions & 15 deletions react/components/Controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default function Controls() {
)

/**
* Update the setting parameters (price, odds, jackpot) , only for the owner
* Update the setting parameters (price, odds, jackpot), only for the owner
* @param {Object} event
*/
const updateContractSettings = async (event) => {
Expand All @@ -176,8 +176,8 @@ export default function Controls() {

updateSettings({
args: [
ethers.utils.parseEther(event.target.price.value),
event.target.odds.value,
ethers.utils.parseEther(event.target.price.value),
ethers.utils.parseEther(event.target.jackpot.value),
],
})
Expand Down Expand Up @@ -223,31 +223,31 @@ export default function Controls() {
</p>
<form onSubmit={updateContractSettings}>
<div className="mt-3 flex">
<label>Price:</label>
<label>Odds:</label>
<input
id="price"
id="odds"
type="number"
step="any"
value={price}
onChange={(e) => setPrice(e.target.value)}
placeholder="Price in Ether"
value={odds}
onChange={(e) => setOdds(e.target.value)}
placeholder="0 - 100"
className="w-full bg-gray-100 text-right"
required
/>
<span>Ξ</span>
<span>%</span>
</div>
<div className="mt-1 flex">
<label>Odds:</label>
<label>Price:</label>
<input
id="odds"
id="price"
type="number"
value={odds}
onChange={(e) => setOdds(e.target.value)}
placeholder="0 - 100"
step="any"
value={price}
onChange={(e) => setPrice(e.target.value)}
placeholder="Price in Ether"
className="w-full bg-gray-100 text-right"
required
/>
<span>%</span>
<span>Ξ</span>
</div>
<div className="mt-1 flex">
<label>Jackpot:</label>
Expand Down

0 comments on commit ee6b2d0

Please sign in to comment.