Skip to content

Instantly share code, notes, and snippets.

View MariusVanDerWijden's full-sized avatar
👷‍♂️
#buidling

Marius van der Wijden MariusVanDerWijden

👷‍♂️
#buidling
View GitHub Profile
This file has been truncated, but you can view the full file.
{"00000001-ecrecovertests-6":{"env":{"currentCoinbase":"b94f5374fce5edbc8e2a8697c15331677e6ebf0b","currentDifficulty":"0x20000","currentGasLimit":"0x26e1f476fe1e22","currentNumber":"0x1","currentTimestamp":"0x3e8","previousHash":"0x0000000000000000000000000000000000000000000000000000000000000000"},"pre":{"0x000000000000000000000000000ca11ec5ec04e5":{"code":"0x7ff6e74c97143e1e70bc39a03b58b8db5334527c4aeb8dcf99c5112b3375a56e556000527f5d766b5ebd2197a054ced2fd86dfb6c9ed7b4017589dbf623c47f705bd318a406020527f85eb8a8e2b03b8d60a4535ff19e5468acedcedc3e19175c9fbf155fefc3b2c816040527f68352b37dadc05492d8bef3e268edf525bfa268a7e8e13b680c7b4e1a2e4d07e606052602060006080600060196007611383f2506000516000557f8dd57e58cdff814ffa83ea24ce78b5c84207ff09553fabc257d58067298b22136000527f247dcd6ebbeabd5eca44cbb228c6efff7c6a5d7303eeee56553ef8abfd5cb7c46020527f117b78b0d5d8de1588c54de03aad03d98725f020bbf837228013c7bf46ff3c866040527f15d3b3a73210dee18f63acfefcc431c37a2d55452e0532ed0fad6e7642a1037d60605260206000608060006007611558f4506000516020
{
"-blaketest-0": {
"env": {
"currentCoinbase": "b94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"currentDifficulty": "0x20000",
"currentGasLimit": "0x26e1f476fe1e22",
"currentNumber": "0x1",
"currentTimestamp": "0x3e8",
"previousHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
tx, tx2, tx3 := new(types.Transaction), new(types.Transaction), new(types.Transaction)
// Send and abort both transactions
backend.SendTransaction(ctx, tx)
backend.SendTransaction(ctx, tx2)
backend.Rollback()
// Commits transaction to the chain
backend.SendTransaction(ctx, tx3)
backend.Commit()
type SimulatedBackend struct {
backends.SimulatedBackend
}
func (s *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error {
if err := s.SimulatedBackend.SendTransaction(ctx, tx); err != nil {
return err
}
s.Commit()
return nil
// Create a new SimulatedBackend with a default allocation
backend := backends.NewSimulatedBackend(core.DefaultGenesisBlock().Alloc, 9000000)
bal, err := backend.BalanceAt(ctx, common.HexToAddress("0x000"), nil)
// Create a meaningful allocation with a faucet secret key
faucetSK, err := crypto.GenerateKey()
faucetAddr := crypto.PubkeyToAddress(faucetSK.PublicKey)
addr := map[common.Address]core.GenesisAccount{
common.BytesToAddress([]byte{1}): {Balance: big.NewInt(1)}, // ECRecover
common.BytesToAddress([]byte{2}): {Balance: big.NewInt(1)}, // SHA256
// Parse event from types.Log
log := *new(types.Log)
event, err := ctr.ParseDeposited(log)
// Watch for a Deposited event
watchOpts := &bind.WatchOpts{Context: ctx, Start: nil}
// Setup a channel for results
channel := make(chan *coolcontract.CoolContractDeposited)
// Start a goroutine which watches new events
go func() {
sub, err := ctr.WatchDeposited(watchOpts, channel)
defer sub.Unsubscribe()
}()
// Receive events from the channel
// Filter for a Deposited event
filterOpts := &bind.FilterOpts{Context: ctx, Start: 9000000, End: nil}
itr, err := ctr.FilterDeposited(filterOpts)
// Loop over all found events
for itr.Next() {
event := itr.Event
// Print out all caller addresses
fmt.Printf(event.Addr.Hex())
}
// Call a pure/view function
callOpts := &bind.CallOpts{Context: ctx, Pending: false}
bal, err := ctr.SeeBalance(callOpts)
// Call a normal function
tx, err := ctr.Deposit(transactOpts)
receipt, err := bind.WaitMined(ctx, backend, tx)
if receipt.Status != types.ReceiptStatusSuccessful {
panic("Call failed")
}
// Deploy a new contract
addr, tx, ctr, err := coolcontract.DeployCoolContract(transactOpts, backend)
// Check if the contract was deployed successfully
_, err = bind.WaitDeployed(ctx, backend, tx)