mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-07 08:23:08 +00:00
Fix formatting
This commit is contained in:
parent
6fc1f69220
commit
0acb393c3b
@ -29,10 +29,7 @@ import
|
||||
./utils_onchain
|
||||
|
||||
suite "Onchain group manager":
|
||||
|
||||
|
||||
setup:
|
||||
# We run Anvil
|
||||
let runAnvil {.used.} = runAnvil()
|
||||
|
||||
var manager {.threadvar.}: OnchainGroupManager
|
||||
@ -92,7 +89,8 @@ suite "Onchain group manager":
|
||||
raise newException(CatchableError, "Failed to deploy test token contract")
|
||||
let TOKEN_ADDRESS = testTokenAddressRes.get()
|
||||
|
||||
let differentContractAddress = waitFor executeForgeContractDeployScripts(privateKey, acc, web3)
|
||||
let differentContractAddress =
|
||||
waitFor executeForgeContractDeployScripts(privateKey, acc, web3)
|
||||
if differentContractAddress.isErr():
|
||||
error "Failed to deploy RLN contract", error = differentContractAddress.error
|
||||
# simulating a change in the contractAddress
|
||||
|
||||
@ -341,7 +341,7 @@ proc approveTokenAllowanceAndVerify*(
|
||||
return allowanceAfter >= amountWei
|
||||
|
||||
proc executeForgeContractDeployScripts*(
|
||||
pk: keys.PrivateKey, acc: Address, web3: Web3
|
||||
pk: keys.PrivateKey, acc: Address, web3: Web3
|
||||
): Future[Result[Address, string]] {.async, gcsafe.} =
|
||||
## Executes a set of foundry forge scripts required to deploy the RLN contract and returns the deployed proxy contract address
|
||||
## submodulePath: path to the submodule containing contract deploy scripts
|
||||
@ -437,7 +437,7 @@ proc executeForgeContractDeployScripts*(
|
||||
let proxyAddressAddress = Address(proxyAddressBytes)
|
||||
|
||||
info "Address of the Proxy contract", proxyAddressAddress
|
||||
|
||||
|
||||
await web3.close()
|
||||
return ok(proxyAddressAddress)
|
||||
|
||||
@ -549,9 +549,9 @@ proc runAnvil*(port: int = 8540, chainId: string = "1234"): Process =
|
||||
"--transaction-block-keeper",
|
||||
"10",
|
||||
"--disable-console-log",
|
||||
"--threads",
|
||||
"--threads",
|
||||
"0",
|
||||
"--no-request-size-limit"
|
||||
"--no-request-size-limit",
|
||||
],
|
||||
options = {poUsePath},
|
||||
)
|
||||
@ -618,7 +618,8 @@ proc setupOnchainGroupManager*(
|
||||
discard await sendMintCall(
|
||||
web3, web3.defaultAccount, TOKEN_ADDRESS, acc, ethToWei(1000.u256), some(0.u256)
|
||||
)
|
||||
let contractAddressRes = await executeForgeContractDeployScripts(privateKey, acc, web3)
|
||||
let contractAddressRes =
|
||||
await executeForgeContractDeployScripts(privateKey, acc, web3)
|
||||
if contractAddressRes.isErr():
|
||||
error "Failed to deploy RLN contract", error = contractAddressRes.error
|
||||
raise newException(CatchableError, "Failed to deploy RLN contract")
|
||||
|
||||
@ -30,11 +30,17 @@ logScope:
|
||||
# using the when predicate does not work within the contract macro, hence need to dupe
|
||||
contract(WakuRlnContract):
|
||||
# this serves as an entrypoint into the rln membership set
|
||||
proc register(idCommitment: UInt256, userMessageLimit: UInt32, idCommitmentsToErase: seq[UInt256])
|
||||
proc register(
|
||||
idCommitment: UInt256, userMessageLimit: UInt32, idCommitmentsToErase: seq[UInt256]
|
||||
)
|
||||
|
||||
# Initializes the implementation contract (only used in unit tests)
|
||||
proc initialize(maxMessageLimit: UInt256)
|
||||
# this event is raised when a new member is registered
|
||||
proc MembershipRegistered(idCommitment: UInt256, membershipRateLimit: UInt256, index: UInt32) {.event.}
|
||||
proc MembershipRegistered(
|
||||
idCommitment: UInt256, membershipRateLimit: UInt256, index: UInt32
|
||||
) {.event.}
|
||||
|
||||
# this function denotes existence of a given user
|
||||
proc isInMembershipSet(idCommitment: Uint256): bool {.view.}
|
||||
# this constant describes the next index of a new member
|
||||
@ -295,17 +301,18 @@ method register*(
|
||||
g.retryWrapper(gasPrice, "Failed to get gas price"):
|
||||
int(await ethRpc.provider.eth_gasPrice()) * 2
|
||||
let idCommitmentHex = identityCredential.idCommitment.inHex()
|
||||
debug "identityCredential idCommitmentHex",
|
||||
idCommitmentNoConvert = idCommitmentHex
|
||||
debug "identityCredential idCommitmentHex", idCommitmentNoConvert = idCommitmentHex
|
||||
let idCommitment = identityCredential.idCommitment.toUInt256()
|
||||
let idCommitmentsToErase: seq[UInt256] = @[]
|
||||
debug "registering the member",
|
||||
idCommitment = idCommitment, userMessageLimit = userMessageLimit, idCommitmentsToErase = idCommitmentsToErase
|
||||
idCommitment = idCommitment,
|
||||
userMessageLimit = userMessageLimit,
|
||||
idCommitmentsToErase = idCommitmentsToErase
|
||||
var txHash: TxHash
|
||||
g.retryWrapper(txHash, "Failed to register the member"):
|
||||
await wakuRlnContract.register(idCommitment, userMessageLimit.stuint(32),idCommitmentsToErase).send(
|
||||
gasPrice = gasPrice
|
||||
)
|
||||
await wakuRlnContract
|
||||
.register(idCommitment, userMessageLimit.stuint(32), idCommitmentsToErase)
|
||||
.send(gasPrice = gasPrice)
|
||||
|
||||
# wait for the transaction to be mined
|
||||
var tsReceipt: ReceiptObject
|
||||
@ -328,7 +335,9 @@ method register*(
|
||||
debug "third topic", firstTopic = firstTopic
|
||||
# the hash of the signature of MembershipRegistered(uint256,uint256,uint32) event is equal to the following hex value
|
||||
if firstTopic !=
|
||||
cast[FixedBytes[32]](keccak.keccak256.digest("MembershipRegistered(uint256,uint256,uint32)").data):
|
||||
cast[FixedBytes[32]](keccak.keccak256.digest(
|
||||
"MembershipRegistered(uint256,uint256,uint32)"
|
||||
).data):
|
||||
raise newException(ValueError, "register: unexpected event signature")
|
||||
|
||||
# the arguments of the raised event i.e., MembershipRegistered are encoded inside the data field
|
||||
@ -567,7 +576,7 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.}
|
||||
# check if the Ethereum client is reachable
|
||||
let ethRpc: Web3 = (await establishConnection(g)).valueOr:
|
||||
return err("failed to connect to Ethereum clients: " & $error)
|
||||
|
||||
|
||||
debug "fetching chainId"
|
||||
var fetchedChainId: UInt256
|
||||
g.retryWrapper(fetchedChainId, "Failed to get the chain id"):
|
||||
@ -599,7 +608,6 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.}
|
||||
debug "contract address",
|
||||
contractAddress = contractAddress, ethContractAddress = g.ethContractAddress
|
||||
|
||||
|
||||
g.ethRpc = some(ethRpc)
|
||||
g.wakuRlnContract = some(wakuRlnContract)
|
||||
|
||||
@ -628,13 +636,10 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.}
|
||||
# now we check on the contract if the commitment actually has a membership
|
||||
let idCommitmentBytes = keystoreCred.identityCredential.idCommitment
|
||||
let idCommitmentUInt256 = keystoreCred.identityCredential.idCommitment.toUInt256()
|
||||
let idCommitmentHex = idCommitmentBytes.inHex()
|
||||
debug "Keystore idCommitment in bytes",
|
||||
idCommitmentBytes = idCommitmentBytes
|
||||
debug "Keystore idCommitment in UInt256 ",
|
||||
idCommitmentUInt256 = idCommitmentUInt256
|
||||
debug "Keystore idCommitment in hex ",
|
||||
idCommitmentHex = idCommitmentHex
|
||||
let idCommitmentHex = idCommitmentBytes.inHex()
|
||||
debug "Keystore idCommitment in bytes", idCommitmentBytes = idCommitmentBytes
|
||||
debug "Keystore idCommitment in UInt256 ", idCommitmentUInt256 = idCommitmentUInt256
|
||||
debug "Keystore idCommitment in hex ", idCommitmentHex = idCommitmentHex
|
||||
let idCommitment = idCommitmentUInt256
|
||||
try:
|
||||
# let membershipExists =
|
||||
@ -663,10 +668,9 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.}
|
||||
tx.chainId = Opt.some(g.chainId)
|
||||
|
||||
let resultBytes = await g.ethRpc.get().provider.eth_call(tx, "latest")
|
||||
debug "resultBytes",
|
||||
resultBytes = resultBytes, len = resultBytes.len
|
||||
debug "resultBytes", resultBytes = resultBytes, len = resultBytes.len
|
||||
if resultBytes.len == 0:
|
||||
return err("No result returned for function call: " & $functionSignature)
|
||||
return err("No result returned for function call: " & $functionSignature)
|
||||
let membershipExists = resultBytes.len == 32 and resultBytes[^1] == 1'u8
|
||||
|
||||
debug "membershipExists", membershipExists = membershipExists
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user