anchor.diff:      ?assertEqual(ok, ?endgame:activate(testpid())),
       ?assert(?endgame:is_active(testpid())).
   
  +test_active_one_assigned() ->
  +    ok = ?endgame:activate(testpid()),
  +    Main = self(),
  +    Pid = spawn_link(fun() ->
  +        ?pending:register(pending()),
  +        ?chunkstate:assigned(0, 0, 1, self(), testpid()),
  +        Main ! assigned,
  +        etorrent_utils:expect(die)
  +    end),
  +    etorrent_utils:expect(assigned),
  +    ?assertEqual({ok, [{0, 0, 1}]}, ?chunkstate:request(1, testset(), testpid())),
  +    ?assertEqual({ok, assigned}, ?chunkstate:request(1, testset(), testpid())),
  +    Pid ! die, etorrent_utils:wait(Pid).
  +
  +test_active_one_dropped() ->
  +    ok = ?endgame:activate(testpid()),
  +    Main = self(),
  +    Pid = spawn_link(fun() ->
  +        ?pending:register(pending()),
  +        ?chunkstate:assigned(0, 0, 1, self(), testpid()),
  +        ?chunkstate:dropped(0, 0, 1, self(), testpid()),
  +        Main ! dropped,
  +        etorrent_utils:expect(die)
  +    end),
  +    etorrent_utils:expect(dropped),
  +    ?assertEqual({ok, [{0, 0, 1}]}, ?chunkstate:request(1, testset(), testpid())),
  +    Pid ! die, etorrent_utils:wait(Pid).
  +
  +test_active_one_fetched() ->
  +    ok = ?endgame:activate(testpid()),
  +    Main = self(),
  +    %% Spawn a separate process to introduce the chunk into endgame
  +    Orig = spawn_link(fun() ->
  +        ?pending:register(pending()),
  +        ?chunkstate:assigned(0, 0, 1, self(), testpid()),
  +        Main ! assigned,
  +        etorrent_utils:expect(die)
  +    end),
  +    etorrent_utils:expect(assigned),
  +    %% Spawn a process that aquires the chunk from endgame and marks it as fetched
  +    Pid = spawn_link(fun() ->
  +        ?pending:register(pending()),
  +        {ok, [{0,0,1}]} = ?chunkstate:request(1, testset(), testpid()),
  +        ?chunkstate:fetched(0, 0, 1, self(), testpid()),
  +        Main ! fetched,
  +        etorrent_utils:expect(die)
  +    end),
  +    etorrent_utils:expect(fetched),
  +    %% Expect endgame to not send out requests for the fetched chunk
  +    ?assertEqual({ok, assigned}, ?chunkstate:request(1, testset(), testpid())),
  +    Pid ! die, etorrent_utils:wait(Pid),
  +    etorrent_utils:ping(pending()),
  +    etorrent_utils:ping(testpid()),
  +    %% Expect endgame to send out request if the chunk is dropped before it's stored
  +    ?assertEqual({ok, [{0, 0, 1}]}, ?chunkstate:request(1, testset(), testpid())).
  +
   
   
   -endif.
  
positive.code:         fun teardown/1, [
      ?_test(test_registers()),
      ?_test(test_starts_inactive()),
      ?_test(test_activated())
      ]}}.
  
  test_registers() ->
  
negative.code: 
  handle_call({chunk, {request, _, Peerset, Pid}}, _, State) ->
      #state{pending=Pending, requests=Requests} = State,
      Request = etorrent_utils:find(
          fun({{Index, _, _}, Peers}) ->
              (etorrent_pieceset:is_member(Index, Peerset))
              andalso (not lists:member(Pid, Peers))
          end, gb_trees:to_list(Requests)),
      case Request of
          false ->
              {reply, {ok, assigned}, State};
          {{Index, Offset, Length}=Chunk, Peers} ->
              etorrent_chunkstate:assigned(Index, Offset, Length, Pid, Pending),
              NewRequests = gb_trees:update(Chunk, [Pid|Peers], Requests),
              NewState = State#state{requests=NewRequests},
              {reply, {ok, [Chunk]}, NewState}
  